def register(request, campaign_id): try: should_redirect = False campaign = None template = 'petition/register_form.html' try: campaign = Campaign.objects.get(pk=campaign_id) except Campaign.DoesNotExist: messages.error(request, _('Campaign you tried to register for, doesn\'t exist.')) if campaign and request.method == 'POST': form = CampaignRegistrationForm(request.POST) if not campaign.is_active: messages.warning(request, _('The chosen campaign is not currently open for new signatures')) return HttpResponseRedirect(request.META.get('HTTP_REFERER', reverse('campaign_list'))) if form.is_valid(): users_email = form.cleaned_data['email'] users_name = form.cleaned_data['name'] if not users_email: messages.error(request, _('Empty email address submited, please submit a valid one')) else: if not campaign.is_valid_domain(users_email): messages.error(request, _('Your email is not listed amongst the domains that are allowed to participate in this campaign!')) elif not campaign.is_registered(users_email): try: signature_request = Signature() signature_request.email = users_email signature_request.name = users_name signature_request.campaign = campaign signature_request.save() # some kind of try / catch around this one? # transaction? yawn. signature_request.send_verify_email() messages.warning(request, _('Your signature is receieved. You MUST click on the link sent to you by email in order for your signature to be approved.')) #template = 'petition/details.html' except Exception, e: messages.error(request, _('Ooops, something went wrong ..')) messages.error(request, e) signature_request.delete() print(str(e)) else: messages.error(request, _('You are already registered to this campaign!')) should_redirect = True else:
def register(request, campaign_id): try: should_redirect = False campaign = None template = 'petition/register_form.html' try: campaign = Campaign.objects.get(pk=campaign_id) except Campaign.DoesNotExist: messages.error(request, 'Campaign you tried to register for, doesn\'t exist.') if campaign and request.method == 'POST': form = CampaignRegistrationForm(request.POST) if form.is_valid(): users_email = form.cleaned_data['email'] if not users_email: messages.error(request, 'Empty email address submited, please submit a valid one') else: if not campaign.is_valid_domain(users_email): messages.error(request, 'Your email is not listed in the alloweded domains that are allowed to participate in this campaign!') elif not campaign.is_registered(users_email): try: signature_request = Signature() signature_request.email = users_email signature_request.campaign = campaign signature_request.save() # some kind of try / catch around this one? # transaction? yawn. signature_request.send_verify_email() messages.success(request, 'Registrering mottatt, vennligst bekreft registrering via lenken som kommer pr. epost!') #template = 'petition/details.html' except Exception, e: messages.error(request, 'Ooops, something went wrong ..') signature_request.delete() print(str(e)) else: messages.error(request, 'You are already registered to this campaign!') should_redirect = True else: