Files
zulip/zephyr/management/commands/generate_invite_links.py
Luke Faraone 905cf9b3ff Always create a new PreregistrationUser in generate_invite_links
Previously if you had been invited twice to use the app this management
command would fail with your address, since the email address was no longer
unique.

Now by unconditionally generating a new PreregistrationUser object we avoid
this problem.

To test, invite a user to Humbug via the webapp twice, then generate an
invite link for them manually. The latter operation used to produce a
traceback, but now works.

(imported from commit b6c816187e6302b3cb3eea2928565b3a12046c4b)
2013-05-31 12:24:30 -04:00

32 lines
1.0 KiB
Python

from __future__ import absolute_import
from optparse import make_option
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
from confirmation.models import Confirmation
from zephyr.models import UserProfile, PreregistrationUser, \
get_user_profile_by_email
class Command(BaseCommand):
help = "Generate activation links for users and print them to stdout."
def handle(self, *args, **options):
duplicates = False
for email in args:
try:
get_user_profile_by_email(email)
print email + ": There is already a user registered with that address."
duplicates = True
continue
except UserProfile.DoesNotExist:
pass
if duplicates:
return
for email in args:
prereg_user = PreregistrationUser(email=email)
prereg_user.save()
print email + ": " + Confirmation.objects.get_link_for_object(prereg_user)