Import old cards and link to members

This commit is contained in:
Tanner Collin 2020-01-09 06:45:32 +00:00
parent aa6c81c48c
commit 1bf5dd182c
4 changed files with 57 additions and 9 deletions

View File

@ -34,3 +34,12 @@ class Transaction(models.Model):
category = models.TextField(blank=True, null=True) category = models.TextField(blank=True, null=True)
account_type = models.TextField(blank=True, null=True) account_type = models.TextField(blank=True, null=True)
info_source = models.TextField(blank=True, null=True) info_source = models.TextField(blank=True, null=True)
class Card(models.Model):
user = models.ForeignKey(User, related_name='cards', blank=True, null=True, on_delete=models.PROTECT)
member_id = models.IntegerField(blank=True, null=True)
card_number = models.CharField(max_length=16, blank=True, null=True)
notes = models.TextField(blank=True, null=True)
last_seen_at = models.DateField(default=date.today, blank=True, null=True)
active_status = models.CharField(max_length=32, blank=True, null=True)

View File

@ -7,16 +7,10 @@ from . import models, old_models
#custom_error = lambda x: ValidationError(dict(non_field_errors=x)) #custom_error = lambda x: ValidationError(dict(non_field_errors=x))
class TransactionSerializer(serializers.ModelSerializer):
class Meta:
model = models.Transaction
fields = '__all__'
class UserSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = User model = User
fields = ['id', 'username', 'email', 'member', 'transactions'] fields = ['id', 'username', 'email', 'member', 'transactions', 'cards']
depth = 1 depth = 1
@ -33,6 +27,12 @@ class AdminMemberSerializer(serializers.ModelSerializer):
read_only_fields = ['id', 'user'] read_only_fields = ['id', 'user']
class TransactionSerializer(serializers.ModelSerializer):
class Meta:
model = models.Transaction
fields = '__all__'
class RegistrationSerializer(RegisterSerializer): class RegistrationSerializer(RegisterSerializer):
first_name = serializers.CharField(max_length=32) first_name = serializers.CharField(max_length=32)
last_name = serializers.CharField(max_length=32) last_name = serializers.CharField(max_length=32)
@ -65,6 +65,11 @@ class RegistrationSerializer(RegisterSerializer):
t.user = user t.user = user
t.save() t.save()
cards = models.Card.objects.filter(member_id=member.id)
for c in cards:
c.user = user
c.save()
else: else:
models.Member.objects.create( models.Member.objects.create(
user=user, user=user,

View File

@ -30,6 +30,15 @@ TRANSACTION_FIELDS = [
'info_source', 'info_source',
] ]
CARD_FIELDS = [
'id',
'member_id',
'card_number',
'notes',
'last_seen_at',
'active_status',
]
print('Deleting all members...') print('Deleting all members...')
models.Member.objects.all().delete() models.Member.objects.all().delete()
@ -66,4 +75,22 @@ for t in old_transactions:
)) ))
print('Deleting all cards...')
models.Card.objects.all().delete()
print('Importing old cards...')
old_cards = old_models.AccessKeys.objects.using('old_portal').all()
for c in old_cards:
new_card = {}
for f in CARD_FIELDS:
new_card[f] = c.__dict__.get(f, None)
models.Card.objects.create(**new_card)
print('Imported #{} - {} {}'.format(
c.id, c.card_number, c.notes
))
print('Done.') print('Done.')

View File

@ -239,7 +239,8 @@ function MemberInfo(props) {
const user = props.user; const user = props.user;
const member = user.member; const member = user.member;
const lastTrans = user.transactions.slice(-3); const lastTrans = user.transactions && user.transactions.slice(-3).reverse();
const lastCard = user.cards && user.cards.sort((a, b) => a.last_seen_at > b.last_seen_at)[0];
return ( return (
<div> <div>
@ -282,9 +283,13 @@ function MemberInfo(props) {
<Table.Cell>{member.vetted_date || 'Not vetted'}</Table.Cell> <Table.Cell>{member.vetted_date || 'Not vetted'}</Table.Cell>
</Table.Row> </Table.Row>
<Table.Row> <Table.Row>
<Table.Cell>Monthly</Table.Cell> <Table.Cell>Monthly:</Table.Cell>
<Table.Cell>${member.monthly_fees || '???'}</Table.Cell> <Table.Cell>${member.monthly_fees || '???'}</Table.Cell>
</Table.Row> </Table.Row>
<Table.Row>
<Table.Cell>Card Number:</Table.Cell>
<Table.Cell>{lastCard && lastCard.card_number || 'None'}</Table.Cell>
</Table.Row>
</Table.Body> </Table.Body>
</Table> </Table>
@ -365,7 +370,9 @@ function App() {
<Menu.Item <Menu.Item
content='Logout' content='Logout'
onClick={logout} onClick={logout}
icon='cancel'
/> />
<Menu.Item fitted content='' />
</Menu.Menu>} </Menu.Menu>}
</Container> </Container>
</Menu> </Menu>