diff options
| author | 2019-10-20 18:05:33 +0100 | |
|---|---|---|
| committer | 2019-10-20 18:05:33 +0100 | |
| commit | 3caa7675f9c5c33b6a8e91c633945d5152383a76 (patch) | |
| tree | 83861cec2808fbdbf87efd68083c6d80137151d5 /pydis_site/apps | |
| parent | Signals: Complete coverage in tests (diff) | |
Update Django users with Discord username+discrim.
This sets both the Django User's `username` and `first_name` params.
Diffstat (limited to 'pydis_site/apps')
| -rw-r--r-- | pydis_site/apps/home/signals.py | 11 | 
1 files changed, 9 insertions, 2 deletions
diff --git a/pydis_site/apps/home/signals.py b/pydis_site/apps/home/signals.py index 43e861d2..4cb4564b 100644 --- a/pydis_site/apps/home/signals.py +++ b/pydis_site/apps/home/signals.py @@ -262,6 +262,13 @@ class AllauthSignalListener:          except SocialAccount.user.RelatedObjectDoesNotExist:              return  # There's no user account yet, this will be handled by another receiver +        # Ensure that the username on this account is correct +        new_username = f"{user.name}#{user.discriminator}" + +        if account.user.username != new_username: +            account.user.username = new_username +            account.user.first_name = new_username +          if not user.in_guild:              deletion = True @@ -278,7 +285,6 @@ class AllauthSignalListener:              if account.user.is_staff:                  # They're marked as a staff user and they shouldn't be, so let's fix that                  account.user.is_staff = False -                account.user.save(update_fields=("is_staff", ))          else:              new_groups = []              is_staff = False @@ -304,4 +310,5 @@ class AllauthSignalListener:              if account.user.is_staff != is_staff:                  account.user.is_staff = is_staff -                account.user.save(update_fields=("is_staff", )) + +        account.user.save()  |