def join(request): """Surface join form""" show_age_gateway = preferences.GeneralPreferences.show_age_gateway \ and not request.COOKIES.get('age_gateway_passed') if request.method == 'POST': form = JoinForm(request.POST, request.FILES, show_age_gateway=show_age_gateway) if form.is_valid(): member = form.save() backend = get_backends()[0] member.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__) login(request, member) response = HttpResponseRedirect(reverse('join-finish')) # Set cookie if age gateway applicable. Can't delegate to form :( if show_age_gateway: now = datetime.datetime.now() expires = now.replace(year=now.year+10) response.set_cookie('age_gateway_passed', value=1, expires=expires) msg = _("You have successfully signed up to the site.") messages.success(request, msg, fail_silently=True) return response else: form = JoinForm(show_age_gateway=show_age_gateway) extra = dict(form=form) return render_to_response('foundry/join.html', extra, context_instance=RequestContext(request))
def join(request): """Surface join form""" show_age_gateway = preferences.GeneralPreferences.show_age_gateway age_gateway_passed = bool(request.COOKIES.get('age_gateway_passed', False)) # pass initial values where possible initial = {} age_gateway_values = request.COOKIES.get('age_gateway_values') if age_gateway_values: initial['country'] = Country.objects.get(country_code=age_gateway_values[0:2]) initial['dob'] = datetime.strptime(age_gateway_values[3:], '%d-%m-%Y') if 'location' in request.session: city = request.session['location']['city'] if 'country' not in initial or city.country.country_code == initial['country'].country_code: try: if 'country' not in initial: initial['country'] = Country.objects.get(country_code=city.country.country_code) initial['city'] = city.name initial['province'] = city.region.name if city.region else '' # foundry countries and atlas aren't synced except Country.DoesNotExist: pass if request.method == 'POST': form = JoinForm(request.POST, request.FILES, show_age_gateway=show_age_gateway, age_gateway_passed=age_gateway_passed, initial=initial) if form.is_valid(): member = form.save() backend = get_backends()[0] member.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__) login(request, member) response = HttpResponseRedirect(reverse('home')) msg = _("You have successfully signed up to the site.") messages.success(request, msg, fail_silently=True) return response else: form = JoinForm(show_age_gateway=show_age_gateway, age_gateway_passed=age_gateway_passed, initial=initial) extra = dict(form=form) return render_to_response('foundry/join.html', extra, context_instance=RequestContext(request))