Commit df083e8e authored by Christophe Siraut's avatar Christophe Siraut
Browse files

Notification functional.

parent b4d02956
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy
def email_notify(author, voter):
print 'a'
user = User.objects.get(username=author)
subject = "Django email notification"
message = "User %s has voted" % voter
user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
print author, user, voter
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") %
message += "\n\n"
message += _("Current results:")
message += "\n\n"
for choice in poll.choice_set.all():
message += "%s: %i" % (choice.choice, choice.votecount)
message += "\n\n"
poll.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
import os
from binascii import hexlify
from django.db import models
......@@ -16,12 +17,15 @@ class Poll(models.Model):
upd_date = models.DateField(auto_now=True)
author = models.CharField(max_length=40)
description = models.CharField(max_length=300)
username = models.OneToOneField(User)
user = models.OneToOneField(User,blank=True,null=True)
m django.contrib.auth.models import User
def __unicode__(self):
return self.title
def link(self):
return 'http://%s/%s/' % (Site.objects.get_current(),
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.DateTimeField()
......@@ -13,16 +13,19 @@ 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.conf import settings
from accounts.views import email_notify
def new(request):
if request.method == 'POST': # If the form has been submitted...
instance = Poll(author=str(request.user))
if request.user.is_authenticated():
instance = Poll(author=str(request.user), user=request.user)
instance = Poll(author=str(request.user))
form = PollForm(request.POST, instance=instance) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
poll_id = form.cleaned_data.get('title') # Process the data in form.cleaned_data
new_poll =
#if not request.user.is_authenticated(): # Anonymous wants to create a poll...
key = 'is_' + + '_author'
request.session[key] = True # This writes cookie
......@@ -218,8 +221,8 @@ def vote(request, poll_id):
error_message = "Your vote has been updated, thank you."
if has_voted:
if poll.username:
email_notify(poll.username, voter)
if poll.user:
email_notify(poll, voter)
error_message = 'Did you forget to provide your name?'
Supports Markdown
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