Link paypal hints when generating users

This commit is contained in:
Tanner Collin 2021-11-28 06:49:02 +00:00
parent b4510831f6
commit cac6a7223f
2 changed files with 37 additions and 37 deletions

View File

@ -324,7 +324,7 @@ class TrainingViewSet(Base, Retrieve, Create, Update):
user = member.user user = member.user
training1 = models.Training.objects.filter(user=user, session=session) training1 = models.Training.objects.filter(user=user, session=session)
if training1.exists() if training1.exists():
raise exceptions.ValidationError(dict(non_field_errors='Already registered.')) raise exceptions.ValidationError(dict(non_field_errors='Already registered.'))
self.update_cert(session, member, status) self.update_cert(session, member, status)

View File

@ -25,61 +25,61 @@ print('Generating Users')
count = 0 count = 0
for member in members: for member in members:
if member.user:
continue
print('Member', member.id, member.first_name, member.last_name) print('Member', member.id, member.first_name, member.last_name)
if not member.first_name.isalpha(): if not member.user:
print(' Non-alpha first name.') print(' No user, generating.')
if not member.last_name.isalpha(): if not member.first_name.isalpha():
print(' Non-alpha last name.') print(' Non-alpha first name.')
first_name = member.first_name.strip().lower() if not member.last_name.isalpha():
last_name = member.last_name.strip().lower() print(' Non-alpha last name.')
first_name = re.sub(r'[^a-z- ]+', '', first_name) first_name = member.first_name.strip().lower()
last_name = re.sub(r'[^a-z- ]+', '', last_name) last_name = member.last_name.strip().lower()
first_name = first_name.replace(' ', '.').replace('-', '.') first_name = re.sub(r'[^a-z- ]+', '', first_name)
last_name = last_name.replace(' ', '.').replace('-', '.') last_name = re.sub(r'[^a-z- ]+', '', last_name)
username = first_name + '.' + last_name first_name = first_name.replace(' ', '.').replace('-', '.')
print(' Username:', username) last_name = last_name.replace(' ', '.').replace('-', '.')
if member.old_email: username = first_name + '.' + last_name
email = member.old_email print(' Username:', username)
else:
email = random_email()
print(' No email, using:', email)
user = User.objects.create_user(username, email, str(uuid4())) if member.old_email:
email = member.old_email
else:
email = random_email()
print(' No email, using:', email)
member.user = user user = User.objects.create_user(username, email, str(uuid4()))
member.save()
x = models.Transaction.objects.filter(member_id=member.id) member.user = user
x.update(user=user) member.save()
print(' Linked', x.count(), 'transactions')
x = models.Card.objects.filter(member_id=member.id) x = models.Transaction.objects.filter(user=None, member_id=member.id)
x.update(user=user) print(' Linking', x.count(), 'transactions')
print(' Linked', x.count(), 'cards') x.update(user=member.user)
x = models.Training.objects.filter(member_id=member.id) x = models.Card.objects.filter(user=None, member_id=member.id)
x.update(user=user) print(' Linking', x.count(), 'cards')
print(' Linked', x.count(), 'trainings') x.update(user=member.user)
x = models.PayPalHint.objects.filter(member_id=member.id) x = models.Training.objects.filter(user=None, member_id=member.id)
x.update(user=user) print(' Linking', x.count(), 'trainings')
print(' Linked', x.count(), 'paypal hints') x.update(user=member.user)
x = models.PayPalHint.objects.filter(user=None, member_id=member.id)
print(' Linking', x.count(), 'paypal hints')
x.update(user=member.user)
count += 1 count += 1
print() print()
print('Generated', count, 'users.') print('Processed', count, 'members.')
print('Deleting orphan cards...') print('Deleting orphan cards...')
count = models.Card.objects.filter(user__isnull=True).delete()[0] count = models.Card.objects.filter(user__isnull=True).delete()[0]