Permalink
Browse files

Integrated Django's messages into edit view

  • Loading branch information...
1 parent dab016b commit 3c4940a887cf85d755146e98b69c434c5439c8d2 @anttihirvonen committed Sep 14, 2012
Showing with 16 additions and 7 deletions.
  1. +6 −6 dotmembership/apps/members/templates/members/edit.html
  2. +10 −1 dotmembership/apps/members/views.py
@@ -2,23 +2,23 @@
{% load bootstrap %}
{% block title %}Hei {{ member.first_name }}!{% endblock %}
{% block site_content %}
-<div class="alert">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <strong>Warning!</strong> Best check yo self, you're not looking too good.
-</div>
<div class="row">
<div class="span12">
<h3>Muokkaa sähköpostiosoitettasi</h3>
<form action="" method="POST" class="form form-horizontal">
{% csrf_token %}
{{ email_form|bootstrap }}
- <button type="submit" name="edit_email" class="btn btn-large">Tallenna</button>
+ <div class="controls">
+ <button type="submit" name="edit_email" class="btn btn-large">Tallenna</button>
+ </div>
</form>
<h3>Muokkaa jäsentietojasi</h3>
<form action="" method="POST" class="form form-horizontal">
{% csrf_token %}
{{ member_form|bootstrap }}
- <button type="submit" name="edit_member" class="btn btn-large">Tallenna</button>
+ <div class="controls">
+ <button type="submit" name="edit_member" class="btn btn-large">Tallenna</button>
+ </div>
</form>
</div>
</div>
@@ -1,7 +1,9 @@
+# encoding: utf-8
from django.shortcuts import render
from django.conf import settings
from django.http import HttpResponseRedirect
from django.core.signing import TimestampSigner, BadSignature, SignatureExpired
+from django.contrib import messages
from generic_confirmation.forms import ConfirmationForm
@@ -107,7 +109,7 @@ def confirm_email_change(request, token):
def edit(request, signed_id):
signer = TimestampSigner()
try:
- id = signer.unsign(signed_id, max_age=30*60) # 30 minutes
+ 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")
@@ -120,12 +122,19 @@ def edit(request, signed_id):
member_form = MemberForm(request.POST, instance=member)
if member_form.is_valid():
member_form.save()
+ messages.success(request, "Jäsentiedot tallennettu.")
return HttpResponseRedirect(request.get_full_path())
+ else:
+ messages.error(request, "Korjaa jäsentiedoissa esiintyvät virheet.")
elif "edit_email" in request.POST:
email_form = MemberEmailEditForm(request.POST, instance=member)
if email_form.is_valid():
email_form.save()
+ messages.success(request, u"Syöttämääsi sähköpostiosoitteeseen %s lähetettiin vahvistusviesti, \
+ josta löytyvää linkkiä sinun tulee käydä klikkaamassa vahvistaaksesi muutoksen." % email_form.cleaned_data["email"])
return HttpResponseRedirect(request.get_full_path())
+ else:
+ messages.error(request, "Korjaa virheet.")
return render(request, "members/edit.html", {"member": member,
"member_form": member_form,

0 comments on commit 3c4940a

Please sign in to comment.