views.py 1.3 KB
Newer Older
1
from django.conf import settings
2 3
from django.shortcuts import render, HttpResponseRedirect
from django.core.urlresolvers import reverse
4
from django.contrib.auth.models import User
5
from django.contrib.auth.decorators import login_required
Christophe Siraut's avatar
Christophe Siraut committed
6
from django.utils.translation import ugettext_lazy
7
from accounts.forms import UserProfileForm
8

Christophe Siraut's avatar
Christophe Siraut committed
9 10 11 12 13 14 15 16 17 18 19 20
def _(string):
    return unicode(ugettext_lazy(string))

def email_notify(poll, voter):
        subject = _("Nuages email notification")
        message = _("User %s has voted") % voter
        message += "\n\n"
        message += _("The link to your poll: %s") % poll.link
        message += "\n\n"
        message += _("Current results:")
        message += "\n\n"
        for choice in poll.choice_set.all():
Christophe Siraut's avatar
Christophe Siraut committed
21
            message += "%s: %i\n" % (choice.choice, choice.votecount)
Christophe Siraut's avatar
Christophe Siraut committed
22
        poll.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
23 24 25 26 27 28 29 30 31 32 33 34 35

@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})