Skip to content
Browse files

Separated member join form from edit form

  • Loading branch information...
1 parent 24099d2 commit 0b02a2dd6277820007e549db560ccec901777dea @anttihirvonen committed Sep 14, 2012
Showing with 33 additions and 13 deletions.
  1. +19 −5 dotmembership/apps/members/forms.py
  2. +14 −8 dotmembership/apps/members/views.py
View
24 dotmembership/apps/members/forms.py
@@ -11,7 +11,25 @@
from .models import Member
-class MemberForm(DeferredForm):
+class MemberForm(forms.ModelForm):
+ """
+ Form for editing an old member. Does not expose
+ email field, as it is defined separately as
+ DeferredForm.
+ """
+ class Meta:
+ model = Member
+ fields = ("first_name", "last_name", "email", "home_town",
+ "school", "major", "class_year")
+
+
+class MemberEmailForm(forms.ModelForm):
+ class Meta:
+ model = Member
+ fields = ("email",)
+
+
+class MemberJoinForm(DeferredForm):
"""
The main form for registering a new member.
"""
@@ -29,7 +47,3 @@ def send_notification(self, user=None, instance=None):
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [self.cleaned_data['email']])
-class MemberEmailForm(forms.ModelForm):
- class Meta:
- model = Member
- fields = ("email",)
View
22 dotmembership/apps/members/views.py
@@ -6,7 +6,7 @@
from ajaxutils.decorators import ajax
-from .forms import MemberForm, MemberEmailForm
+from .forms import MemberForm, MemberEmailForm, MemberJoinForm
from .models import Member
from dotmembership.apps.billing.models import Invoice
@@ -19,7 +19,7 @@ def index(request):
Renders a page which contains forms for joining and
sending a self edit link
"""
- member_form = MemberForm()
+ member_form = MemberJoinForm()
email_form = MemberEmailForm()
return render(request, 'index.html', {'member_form': member_form,
@@ -31,7 +31,7 @@ def join(request):
"""
AJAX view for adding a new member to registry.
"""
- form = MemberForm(request.POST)
+ form = MemberJoinForm(request.POST)
if form.is_valid():
form.save()
@@ -95,14 +95,20 @@ def confirm_join(request, token):
def edit(request, signed_id):
signer = TimestampSigner()
try:
- signer.unsign(signed_id, max_age=10)
- except (BadSignature, SignatureExpired):
+ id = signer.unsign(signed_id, max_age=30*60) # 30 minutes
+ member = Member.objects.get(pk=id)
+ except (BadSignature, SignatureExpired, Member.DoesNotExist):
return render(request, "members/edit_failed.html")
if request.method == "POST":
- pass
-
- return render(request, "members/edit.html")
+ form = MemberForm(request.POST, instance=member)
+ if form.is_valid():
+ form.save()
+ else:
+ form = MemberForm(instance=member)
+
+ return render(request, "members/edit.html", {"member": member,
+ "member_form": form })
def check_my_data(request):

0 comments on commit 0b02a2d

Please sign in to comment.
Something went wrong with that request. Please try again.