def signup(request, template='launch/signup_page.html'): if "POST" == request.method: signup_form = SignupForm(data=request.POST) if signup_form.is_valid(): signup_form.save() return HttpResponseRedirect(reverse('launch_page_success')) else: signup_form = SignupForm() context = { 'signup_form' : signup_form, } return render_to_response(template, context, context_instance=RequestContext(request))
def signup(request, template='launch/signup_page.html'): if "POST" == request.method: signup_form = SignupForm(data=request.POST) if signup_form.is_valid(): #If an email has already been entered, let's pull the data from the original request and use that try: signuprequest = SignupRequest.objects.get(email=signup_form.cleaned_data['email']) except: #If no email, let's send the user an email and create a new signup request signuprequest = signup_form.save(commit=False) signuprequest.ip_address = request.META['REMOTE_ADDR'] signuprequest.save() email_context = { 'site' : Site.objects.get_current(), 'signuprequest' : signuprequest } subject = render_to_string('launch/email_subject.txt', email_context) text_body = render_to_string('launch/email_text.txt', email_context) email = EmailMultiAlternatives(subject, text_body, settings.DEFAULT_FROM_EMAIL, [signuprequest.email]) email.attach_alternative(render_to_string('launch/email_html.html', email_context), "text/html") email.send() launch_email = getattr(settings, 'LAUNCH_EMAIL_COPY', None) if launch_email is not None: email_context = { 'site' : Site.objects.get_current(), 'signuprequest' : signuprequest } subject = render_to_string('launch/copy_email_subject.txt', email_context) text_body = render_to_string('launch/copy_email_text.txt', email_context) email = EmailMessage(subject, text_body, settings.DEFAULT_FROM_EMAIL, [launch_email]) email.send() request.session['signup_hash'] = signuprequest.hash_value return HttpResponseRedirect(reverse('launch_page_success_with_id', args=[signuprequest.hash_value])) else: initial = {} if "referredBy" in request.GET: initial['referred_by_id'] = request.GET['referredBy'] signup_form = SignupForm(initial = initial) context = { 'signup_form' : signup_form, } return render_to_response(template, context, context_instance=RequestContext(request))