Import old cards and link to members
This commit is contained in:
parent
aa6c81c48c
commit
1bf5dd182c
|
@ -34,3 +34,12 @@ class Transaction(models.Model):
|
|||
category = models.TextField(blank=True, null=True)
|
||||
account_type = 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)
|
||||
|
|
|
@ -7,16 +7,10 @@ from . import models, old_models
|
|||
|
||||
#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 Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'email', 'member', 'transactions']
|
||||
fields = ['id', 'username', 'email', 'member', 'transactions', 'cards']
|
||||
depth = 1
|
||||
|
||||
|
||||
|
@ -33,6 +27,12 @@ class AdminMemberSerializer(serializers.ModelSerializer):
|
|||
read_only_fields = ['id', 'user']
|
||||
|
||||
|
||||
class TransactionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.Transaction
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class RegistrationSerializer(RegisterSerializer):
|
||||
first_name = serializers.CharField(max_length=32)
|
||||
last_name = serializers.CharField(max_length=32)
|
||||
|
@ -65,6 +65,11 @@ class RegistrationSerializer(RegisterSerializer):
|
|||
t.user = user
|
||||
t.save()
|
||||
|
||||
cards = models.Card.objects.filter(member_id=member.id)
|
||||
for c in cards:
|
||||
c.user = user
|
||||
c.save()
|
||||
|
||||
else:
|
||||
models.Member.objects.create(
|
||||
user=user,
|
||||
|
|
|
@ -30,6 +30,15 @@ TRANSACTION_FIELDS = [
|
|||
'info_source',
|
||||
]
|
||||
|
||||
CARD_FIELDS = [
|
||||
'id',
|
||||
'member_id',
|
||||
'card_number',
|
||||
'notes',
|
||||
'last_seen_at',
|
||||
'active_status',
|
||||
]
|
||||
|
||||
print('Deleting all members...')
|
||||
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.')
|
||||
|
|
|
@ -239,7 +239,8 @@ function MemberInfo(props) {
|
|||
const user = props.user;
|
||||
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 (
|
||||
<div>
|
||||
|
@ -282,9 +283,13 @@ function MemberInfo(props) {
|
|||
<Table.Cell>{member.vetted_date || 'Not vetted'}</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Monthly</Table.Cell>
|
||||
<Table.Cell>Monthly:</Table.Cell>
|
||||
<Table.Cell>${member.monthly_fees || '???'}</Table.Cell>
|
||||
</Table.Row>
|
||||
<Table.Row>
|
||||
<Table.Cell>Card Number:</Table.Cell>
|
||||
<Table.Cell>{lastCard && lastCard.card_number || 'None'}</Table.Cell>
|
||||
</Table.Row>
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
|
@ -365,7 +370,9 @@ function App() {
|
|||
<Menu.Item
|
||||
content='Logout'
|
||||
onClick={logout}
|
||||
icon='cancel'
|
||||
/>
|
||||
<Menu.Item fitted content='' />
|
||||
</Menu.Menu>}
|
||||
</Container>
|
||||
</Menu>
|
||||
|
|
Loading…
Reference in New Issue
Block a user