Don't duplicate realm query when registering

(imported from commit b1e3b7144f564c5b2fc23fbf548bf0672deb2932)
This commit is contained in:
Keegan McAllister 2012-10-11 10:57:47 -04:00
parent 97e3c36d4b
commit 48ec15c46d
1 changed files with 5 additions and 4 deletions

View File

@ -101,12 +101,13 @@ def register(request):
full_name = strip_html(form.cleaned_data['full_name']) full_name = strip_html(form.cleaned_data['full_name'])
short_name = strip_html(email.split('@')[0]) short_name = strip_html(email.split('@')[0])
domain = strip_html(form.cleaned_data['domain']) domain = strip_html(form.cleaned_data['domain'])
realm = Realm.objects.filter(domain=domain)
if not realm: try:
realm = Realm.objects.get(domain=domain)
except Realm.DoesNotExist:
realm = Realm(domain=domain) realm = Realm(domain=domain)
realm.save() realm.save()
else:
realm = Realm.objects.get(domain=domain)
# FIXME: sanitize email addresses # FIXME: sanitize email addresses
create_user(email, password, realm, full_name, short_name) create_user(email, password, realm, full_name, short_name)
login(request, authenticate(username=email, password=password)) login(request, authenticate(username=email, password=password))