From 48ec15c46d2ecf5f1aa97f9c431d0a9a8f883a14 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Thu, 11 Oct 2012 10:57:47 -0400 Subject: [PATCH] Don't duplicate realm query when registering (imported from commit b1e3b7144f564c5b2fc23fbf548bf0672deb2932) --- zephyr/views.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zephyr/views.py b/zephyr/views.py index a60bcdb0c3..549bf6e848 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -101,12 +101,13 @@ def register(request): full_name = strip_html(form.cleaned_data['full_name']) short_name = strip_html(email.split('@')[0]) 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.save() - else: - realm = Realm.objects.get(domain=domain) + # FIXME: sanitize email addresses create_user(email, password, realm, full_name, short_name) login(request, authenticate(username=email, password=password))