Commit d2e69403 authored by Christophe Siraut's avatar Christophe Siraut

Add templates and plumbing for notifications.

parent 88cbcf49
*.sqlite
*.pyc
*~
fix
fix*
settings.py
staticroot
......@@ -97,7 +97,7 @@ Fix permission for apache user
sudo chown -R www-data /usr/local/lib/nuages
Set domain name: login to the /admin/ url of your installation, modify the "Site" entry from "example.com" to your domain name.
Set domain name: login to /admin/sites/site/1/ and modify the entry from "example.com" to your domain name.
Email Service
=============
......@@ -113,3 +113,15 @@ Another option is to add attributes in settings.py, this make email work only wh
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = False
Migrations
==========
When models change, we need to perform some manual steps to keep existing data:
# mkdir fixture
# ./manage.py dumpdata sondage --indent=2 > fixture/sondage.json
# ./manage.py dumpdata accounts --indent=2 > fixture/accounts.json
# git pull
# ./manage.py reset sondage accounts
# ./manage.py syncdb
# ./manage.py loaddata < fixture/*.json
......@@ -4,5 +4,5 @@ from accounts.models import UserProfile
class UserProfileForm(ModelForm):
class Meta:
model = UserProfile
fields = ('email_notification',)
fields = ('email_notifications',)
......@@ -4,7 +4,7 @@ from django.contrib.auth.signals import user_logged_in
class UserProfile(models.Model):
user = models.OneToOneField(User)
email_notification = models.BooleanField()
email_notifications = models.BooleanField()
def login_handler(user, **kwargs):
try:
......
from django.conf import settings
from django.shortcuts import render, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext_lazy
from accounts.forms import UserProfileForm
def _(string):
return unicode(ugettext_lazy(string))
......@@ -16,3 +20,16 @@ def email_notify(poll, voter):
for choice in poll.choice_set.all():
message += "%s: %i\n" % (choice.choice, choice.votecount)
poll.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
@login_required
def profile(request):
if request.method == 'POST':
form = UserProfileForm(request.POST)
if form.is_valid():
for k,v in form.cleaned_data.iteritems():
setattr(request.user.userprofile, k, v)
request.user.userprofile.save()
return HttpResponseRedirect(reverse('home'))
form = UserProfileForm()
return render(request, "form.html", {'form': form})
......@@ -11,7 +11,7 @@ from sondage.models import Poll, Choice, Vote, Bulletin
from sondage.forms import PollForm, ChoiceForm, VoteForm, BulletinForm
from django.views.generic.create_update import update_object
from django.contrib.auth.decorators import login_required
#from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from accounts.views import email_notify
from accounts.forms import UserProfileForm
......@@ -119,7 +119,7 @@ def editchoices(request, poll_id):
return HttpResponseRedirect(redir)
else:
#vforms=OrderedItemFormset(request.POST, instance=poll)
error_message = "There are some errors in the form you posted."
error_message = _("There are some errors in the form you posted.")
vforms=instances
else:
......@@ -220,16 +220,19 @@ def vote(request, poll_id):
old.voice = vorm.cleaned_data['voice']
old.comment = vorm.cleaned_data['comment']
old.save()
error_message = "Your vote has been updated, thank you."
if has_voted:
if poll.user:
error_message = _("Your vote has been updated, thank you.")
if has_voted and poll.user:
try:
if poll.user.userprofile.email_notifications:
email_notify(poll, voter)
except:
pass
else:
error_message = 'Did you forget to provide your name?'
error_message = _('Did you forget to provide your name?')
else:
#error_message = form.errors
error_message = 'Did you forget to provide your name?'
voter = 'your name'
error_message = _('Did you forget to provide your name?')
voter = _('your name')
else: # request.method = 'GET'
......@@ -258,7 +261,7 @@ def vote(request, poll_id):
pass
else:
voter = ''
error_message = "Login let you modify your vote anytime."
error_message = _("Login let you modify your vote anytime.")
key = 'has_voted-' + poll.id
if request.session.get(key, False):
has_voted = True # Used to show "Forget me"
......
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form action="." method="post">
{% csrf_token %}
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field }} {{ field.help_text }}
</div>
{% endfor %}
<br />
<div class="form-actions">
<p><input type="submit" value={% trans 'Send' %} /><p>
</div>
</form>
{% endblock %}
......@@ -49,6 +49,7 @@
<h2>{% trans "My account" %}</h2>
<ul>
<li>{% trans "Username" %}: {{user}}</li>
<li><a href="{% url 'profile' %}">{% trans 'Email notifications' %}</a>: {{ user.userprofile.email_notifications }}</li>
<li><a href="{% url 'auth_password_change' %}">{% trans 'Change password' %}</a></li>
<!--<li><a href="/user/email/change/">{% trans 'Change email address' %}</a></li>-->
<li><a href="{% url 'auth_logout' %}">{% trans 'Logout' %}</a></li>
......
......@@ -9,7 +9,7 @@
<input type="submit" value="{% trans 'Log in' %}" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
<br />
<p>{% trans "Forgot password" %}? <a href="{% url auth_password_reset %}">{% trans "Reset it" %}</a>!</p>
<p>{% trans "Not member" %}? <a href="{% url registration_register %}">{% trans "Register" %}</a>!</p>
{% endblock %}
......@@ -31,6 +31,7 @@ urlpatterns = patterns('',
url(r'^(?P<poll_id>\w+)/edit/choices/$', 'sondage.views.editchoices'),
url(r'^(?P<poll_id>\w{4})/vote/$', 'sondage.views.vote'),
url(r'^(?P<poll_id>\w+)/csv/$', 'sondage.views.exp_csv'),
url(r'^accounts/profile/$', 'accounts.views.profile', name='profile'),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^(?P<poll_id>\w{4})/clear/', 'sondage.userviews.clear_cookie'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment