From 466c664b680ab6ae9008b3ef384901495fc3e12f Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 1 Apr 2016 11:41:59 +1100 Subject: [PATCH] factor out handle_profile --- registrasion/views.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/registrasion/views.py b/registrasion/views.py index b0f7093e..a5db062a 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -66,6 +66,16 @@ def guided_registration(request, page_id=0): @login_required def edit_profile(request): + form, handled = handle_profile(request, "profile") + + data = { + "form": form, + } + return render(request, "registrasion/profile_form.html", data) + +def handle_profile(request, prefix): + ''' Returns a profile form instance, and a boolean which is true if the + form was handled. ''' attendee = rego.Attendee.get_instance(request.user) try: @@ -73,17 +83,21 @@ def edit_profile(request): except ObjectDoesNotExist: profile = None - form = forms.ProfileForm(request.POST or None, instance=profile) + # TODO: pull down the speaker's real name from the Speaker profile + + form = forms.ProfileForm( + request.POST or None, + instance=profile, + prefix=prefix + ) + + handled = True if request.POST else False if request.POST and form.is_valid(): form.instance.attendee = attendee form.save() - data = { - "form": form, - } - return render(request, "registrasion/profile_form.html", data) - + return form, handled @login_required def product_category(request, category_id):