Skip to content

Commit

Permalink
v1 of address forwarding
Browse files Browse the repository at this point in the history
stashing changes, still needs lots of testing
  • Loading branch information
Michael Flaxman committed Apr 23, 2015
1 parent 744e3b8 commit 266d3c1
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 17 deletions.
30 changes: 28 additions & 2 deletions addresses/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from addresses.models import AddressSubscription
from addresses.models import AddressSubscription, AddressForwarding

from blockcypher.constants import COIN_CHOICES

Expand Down Expand Up @@ -55,9 +55,10 @@ def coin_symbol(self, instance):
'notify_on_withdrawal',
'auth_user',
'blockcypher_id',
'address_forwarding_obj',
)

raw_id_fields = ('auth_user', )
raw_id_fields = ('auth_user', 'address_forwarding_obj', )
search_fields = ('b58_address', 'auth_user__email', )
list_filter = (
CSFilter,
Expand All @@ -67,3 +68,28 @@ def coin_symbol(self, instance):
'notify_on_deposit',
'notify_on_withdrawal',
)


@admin.register(AddressForwarding)
class AddressForwardingAdmin(admin.ModelAdmin):

def coin_symbol(self, instance):
return self.coin_symbol
coin_symbol.allow_tags = True

list_display = (
'id',
'created_at',
'archived_at',
'coin_symbol',
'initial_address',
'destination_address',
'auth_user',
'blockcypher_id',
)

raw_id_fields = ('auth_user', )
search_fields = ('initial_address', 'destination_address', )
list_filter = (
CSFilter,
)
25 changes: 24 additions & 1 deletion addresses/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,27 @@ class AddressSearchForm(KnownUserAddressSubscriptionForm):

def __init__(self, *args, **kwargs):
super(AddressSearchForm, self).__init__(*args, **kwargs)
self.fields['coin_address'].label = "Address"
self.fields['coin_address'].label = _("Address")


class KnownUserAddressForwardingForm(KnownUserAddressSubscriptionForm):
wants_email_notification = forms.EmailField(
label=_('Recieve Email Notification for Transactions'),
initial=True,
)

def __init__(self, *args, **kwargs):
super(KnownUserAddressForwardingForm, self).__init__(*args, **kwargs)
self.fields['coin_address'].label = _("Address to Forward To")
self.fields['coin_address'].help_text = _('We will generate a new address that will automatically forward to this address')


class NewUserAddressForwardingForm(NewUserAddressSubscriptionForm):

def __init__(self, *args, **kwargs):
super(NewUserAddressForwardingForm, self).__init__(*args, **kwargs)
self.fields['coin_address'].label = _("Address to Forward To")
self.fields['coin_address'].help_text = _('We will generate a new address that will automatically forward to this address')
self.fields['email'].required = False
self.fields['email'].label = _('Email to Receive Notices (strongly recommended)')
self.fields['email'].help_text = _('If you do not supply an email address, you will have to monitor the Blockchain yourself for incoming transactions')
38 changes: 38 additions & 0 deletions addresses/migrations/0004_auto_20150422_2306.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('addresses', '0003_auto_20150331_1844'),
]

operations = [
migrations.CreateModel(
name='AddressForwarding',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('archived_at', models.DateTimeField(db_index=True, blank=True, null=True)),
('coin_symbol', models.CharField(choices=[('btc', 'Bitcoin'), ('btc-testnet', 'Bitcoin Testnet'), ('ltc', 'Litecoin'), ('doge', 'Dogecoin'), ('uro', 'Uro'), ('bcy', 'BlockCypher Testnet')], db_index=True, max_length=16)),
('initial_address', models.CharField(db_index=True, max_length=64)),
('destination_address', models.CharField(db_index=True, max_length=64)),
('blockcypher_id', models.CharField(db_index=True, max_length=64)),
('auth_user', models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, blank=True)),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='addresssubscription',
name='address_forwarding_obj',
field=models.ForeignKey(to='addresses.AddressForwarding', null=True, blank=True),
preserve_default=True,
),
]
46 changes: 44 additions & 2 deletions addresses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AddressSubscription(models.Model):
notify_on_withdrawal = models.BooleanField(db_index=True, default=True)
auth_user = models.ForeignKey('users.AuthUser', blank=False, null=False)
blockcypher_id = models.CharField(max_length=64, null=False, blank=False, db_index=True)
address_forwarding_obj = models.ForeignKey('addresses.AddressForwarding', blank=True, null=True)

def __str__(self):
return '%s to %s' % (self.id, self.b58_address)
Expand All @@ -27,8 +28,8 @@ def get_currency_abbrev(self):
def get_currency_display_name(self):
return COIN_SYMBOL_MAPPINGS[self.coin_symbol]['display_name']

def send_welcome_email(self):
# TODO: add abuse check so you can only send this email to an unconvirmed user X times
def send_notifications_welcome_email(self):
# TODO: add abuse check so you can only send this email to an unconfirmed user X times
b58_address = self.b58_address
context_dict = {
'b58_address': b58_address,
Expand All @@ -41,3 +42,44 @@ def send_welcome_email(self):
body_context=context_dict,
fkey_objs={'address_subscription': self},
)


class AddressForwarding(models.Model):
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
archived_at = models.DateTimeField(blank=True, null=True, db_index=True)
coin_symbol = models.CharField(choices=COIN_CHOICES, max_length=16, null=False, blank=False, db_index=True)
initial_address = models.CharField(blank=False, null=False, max_length=64, db_index=True)
destination_address = models.CharField(blank=False, null=False, max_length=64, db_index=True)
auth_user = models.ForeignKey('users.AuthUser', blank=True, null=True)
blockcypher_id = models.CharField(max_length=64, null=False, blank=False, db_index=True)

def __str__(self):
return '%s to %s' % (self.initial_address, self.destination_address)

def get_currency_abbrev(self):
return COIN_SYMBOL_MAPPINGS[self.coin_symbol]['currency_abbrev']

def get_currency_display_name(self):
return COIN_SYMBOL_MAPPINGS[self.coin_symbol]['display_name']

def send_forwarding_welcome_email(self):
# TODO: add abuse check so you can only send this email to an unconfirmed user X times

if not self.auth_user:
return

context_dict = {
'initial_address': self.initial_address,
'destination_address': self.destination_address,
'cs_display': COIN_SYMBOL_MAPPINGS[self.coin_symbol]['display_name']
}
fkey_objs = {
'address_forwarding': self,
}
return send_and_log(
subject='Please Confirm Your Email Subscription to %s' % self.initial_address,
body_template='new_user_forwarding.html',
to_user=self.auth_user,
body_context=context_dict,
fkey_objs=fkey_objs,
)
Loading

0 comments on commit 266d3c1

Please sign in to comment.