Profile form view now edits the relevant form
This commit is contained in:
parent
236c61eefa
commit
05923a9a8f
3 changed files with 26 additions and 3 deletions
|
@ -21,6 +21,18 @@ class Attendee(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s" % self.user
|
return "%s" % self.user
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_instance(user):
|
||||||
|
''' Returns the instance of attendee for the given user, or creates
|
||||||
|
a new one. '''
|
||||||
|
attendees = Attendee.objects.filter(user=user)
|
||||||
|
if len(attendees) > 0:
|
||||||
|
return attendees[0]
|
||||||
|
else:
|
||||||
|
attendee = Attendee(user=user)
|
||||||
|
attendee.save()
|
||||||
|
return attendee
|
||||||
|
|
||||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
# Badge/profile is linked
|
# Badge/profile is linked
|
||||||
completed_registration = models.BooleanField(default=False)
|
completed_registration = models.BooleanField(default=False)
|
||||||
|
|
|
@ -6,7 +6,7 @@ urlpatterns = patterns(
|
||||||
url(r"^checkout$", "checkout", name="checkout"),
|
url(r"^checkout$", "checkout", name="checkout"),
|
||||||
url(r"^invoice/([0-9]+)$", "invoice", name="invoice"),
|
url(r"^invoice/([0-9]+)$", "invoice", name="invoice"),
|
||||||
url(r"^invoice/([0-9]+)/pay$", "pay_invoice", name="pay_invoice"),
|
url(r"^invoice/([0-9]+)/pay$", "pay_invoice", name="pay_invoice"),
|
||||||
url(r"^profile$", "profile", name="profile"),
|
url(r"^profile$", "edit_profile", name="profile"),
|
||||||
url(r"^register$", "guided_registration", name="guided_registration"),
|
url(r"^register$", "guided_registration", name="guided_registration"),
|
||||||
url(r"^register/([0-9]+)$", "guided_registration", name="guided_registration"),
|
url(r"^register/([0-9]+)$", "guided_registration", name="guided_registration"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -39,9 +39,20 @@ def guided_registration(request, page_id=0):
|
||||||
return redirect("dashboard")
|
return redirect("dashboard")
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profile(request):
|
def edit_profile(request):
|
||||||
|
attendee = rego.Attendee.get_instance(request.user)
|
||||||
|
|
||||||
|
try:
|
||||||
|
profile = rego.BadgeAndProfile.objects.get(attendee=attendee)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
profile = None
|
||||||
|
|
||||||
|
form = forms.ProfileForm(request.POST or None, instance=profile)
|
||||||
|
|
||||||
|
if request.POST and form.is_valid():
|
||||||
|
form.instance.attendee = attendee
|
||||||
|
form.save()
|
||||||
|
|
||||||
form = forms.ProfileForm()
|
|
||||||
data = {
|
data = {
|
||||||
"form": form,
|
"form": form,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue