diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index 4f43e42..f1cb54a 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -42,6 +42,7 @@ import errno import hashlib import random +import datetime class UserMailmanSettingsView(MailmanUserView): @@ -237,9 +238,20 @@ if form.is_valid(): email_str = form.cleaned_data['email'].encode('utf-8') activation_key = hashlib.sha1(str(random.random())+email_str).hexdigest() - defaults = {'activation_key': activation_key,} - profile, created = AddressConfirmationProfile.objects.update_or_create( - email=form.cleaned_data['email'], user=request.user, defaults=defaults) + + # XXX Use the following when django 1.6 is dropped as a dependency + # It is more efficient because it can be done in one database operation + # + # defaults = {'activation_key': activation_key,} + # profile, created = AddressConfirmationProfile.objects.update_or_create( + # email=form.cleaned_data['email'], user=request.user, defaults=defaults) + try: + profile = AddressConfirmationProfile.objects.get(email=form.cleaned_data['email'], user=request.user) + profile.activation_key = activation_key + profile.created = datetime.datetime.now() + profile.save() + except AddressConfirmationProfile.DoesNotExist: + profile = AddressConfirmationProfile.objects.create_profile(email=form.cleaned_data['email'], user=request.user) try: profile.send_confirmation_link(request) messages.success(request,