def edit(request, activation_key=None): if request.user.is_authenticated() or activation_key: if activation_key: #grab user try: user = RegistrationProfile.objects.get(activation_key=activation_key).user except RegistrationProfile.DoesNotExist: user = None else: user = request.user if not user: return render_to_response('registration/activate.html', { } , context_instance=RequestContext(request)) profile = user.get_profile() if request.method == 'POST': form = EditFormSocio(request.POST, request.FILES, request=request, activation_key=activation_key, activating_user=user) if form.is_valid(): if activation_key: activate(request, backend='base.regbackend.FusolabBackend', activation_key=activation_key) user.is_active = True user.save() form.do_save(user=user) return render_to_response('registration/edit_complete.html', { 'activation_key': activation_key} , context_instance=RequestContext(request)) else: if profile.born_date: mydate = profile.born_date.strftime('%d/%m/%Y') else: mydate = '' init_dict={ 'first_name': user.first_name, 'last_name': user.last_name, 'username': user.username, 'email': user.email, 'born_date': mydate, 'born_place': profile.born_place, 'doc_type': profile.doc_type, 'doc_id': profile.doc_id, 'how_hear': profile.how_hear, 'salutatore': profile.salutatore, 'photo': profile.photo, } if activation_key: init_dict.pop('username') #force users to choose a username form = EditFormSocio(initial=init_dict, request=request) #create empty form return render_to_response('registration/edit.html', {'form': form, 'activation_key': activation_key} , context_instance=RequestContext(request)) else: #user is not authenticated or no activation key is provided return HttpResponseRedirect("/accounts/login/")
def activate(request, activation_key, **kwargs): if request.user.is_authenticated(): request.user.message_set.create(message="You are already logged in.") return HttpResponseRedirect(reverse('profiles_create_profile')) return reg_views.activate(request, activation_key, **kwargs)
def activate(request, activation_key): response = registration_views.activate( request, activation_key=activation_key, backend="registration.backends.default.DefaultBackend", template_name="users/activate.html", success_url=reverse("home"), ) if response.status_code == 302: messages.success(request, "Account activated; now you can login.") return response
def edit(request, activation_key=None): if request.user.is_authenticated() or activation_key: if activation_key: #grab user try: user = RegistrationProfile.objects.get( activation_key=activation_key).user except RegistrationProfile.DoesNotExist: user = None else: user = request.user if not user: return render_to_response('registration/activate.html', {}, context_instance=RequestContext(request)) profile = user.get_profile() if request.method == 'POST': form = EditFormSocio(request.POST, request.FILES, request=request, activation_key=activation_key, activating_user=user) if form.is_valid(): if activation_key: activate(request, backend='base.regbackend.FusolabBackend', activation_key=activation_key) user.is_active = True user.save() form.do_save(user=user) return render_to_response( 'registration/edit_complete.html', {'activation_key': activation_key}, context_instance=RequestContext(request)) else: if profile.born_date: mydate = profile.born_date.strftime('%d/%m/%Y') else: mydate = '' init_dict = { 'first_name': user.first_name, 'last_name': user.last_name, 'username': user.username, 'email': user.email, 'born_date': mydate, 'born_place': profile.born_place, 'doc_type': profile.doc_type, 'doc_id': profile.doc_id, 'how_hear': profile.how_hear, 'salutatore': profile.salutatore, 'photo': profile.photo, } if activation_key: init_dict.pop('username') #force users to choose a username form = EditFormSocio(initial=init_dict, request=request) #create empty form return render_to_response('registration/edit.html', { 'form': form, 'activation_key': activation_key }, context_instance=RequestContext(request)) else: #user is not authenticated or no activation key is provided return HttpResponseRedirect("/accounts/login/")