From c1179cc913cce18c7d5a317da15363c3118ca1d7 Mon Sep 17 00:00:00 2001 From: etienne Date: Wed, 3 Dec 2008 13:35:22 +0000 Subject: First version of syndication. Change on the css --- polls/models.py | 5 +++++ polls/views.py | 19 ++++++++++++++++++- static/styles.css | 19 +++++++++++++++++++ templates/vote.html | 9 +++++++-- urls.py | 10 +++++++++- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/polls/models.py b/polls/models.py index d76acaa..acc51d5 100644 --- a/polls/models.py +++ b/polls/models.py @@ -53,13 +53,18 @@ class Poll(models.Model): pass class Meta: ordering = ['-modification_date'] + def __unicode__(self): + return self.name class Voter(models.Model): user = models.ForeignKey(PollUser) poll = models.ForeignKey(Poll) creation_date = models.DateTimeField(auto_now_add=True) + modification_date = models.DateTimeField(auto_now=True) class Meta: ordering = ['creation_date'] + def __unicode__(self): + return _("Vote from %(user)s") % {'user':self.user.name} class Choice(models.Model): poll = models.ForeignKey(Poll) diff --git a/polls/views.py b/polls/views.py index 11cad2e..629caa1 100644 --- a/polls/views.py +++ b/polls/views.py @@ -24,6 +24,7 @@ Views management from random import choice as random_choice import string import time +from datetime import datetime from django.utils.translation import gettext_lazy as _ from django.shortcuts import render_to_response @@ -200,7 +201,9 @@ admin_url=admin_url, status = 'D', type=request.POST['poll_type']) def poll(request, poll_url): """Display a poll - poll_url is given to identify the poll + poll_url is given to identify the poll. If '_' is in the poll_url the second + part of the url is the unix time given to highlight a particular vote + modification """ def modifyVote(request, choices): @@ -337,6 +340,15 @@ def poll(request, poll_url): response_dct, redirect = getBaseResponse(request) if redirect: return redirect + highlight_vote_date = None + if '_' in poll_url: + url_spl = poll_url.split('_') + if len(url_spl) == 2: + poll_url, highlight_vote_date = url_spl + try: + highlight_vote_date = int(highlight_vote_date) + except ValueError: + highlight_vote_date = None try: poll = Poll.objects.filter(base_url=poll_url)[0] except IndexError: @@ -370,6 +382,7 @@ def poll(request, poll_url): 'poll_type':poll.type, 'poll_name':poll.name, 'poll_desc':poll.description, + 'poll_base_url':poll.base_url, 'VOTE':Vote.VOTE,}) response_dct['base_url'] = "/".join(request.path.split('/')[:-2]) \ + '/%s/' % poll.base_url @@ -380,6 +393,10 @@ def poll(request, poll_url): choice.sum = 0 choice_ids = [choice.id for choice in choices] for voter in voters: + # highlight a voter + if time.mktime(voter.modification_date.timetuple()) \ + == highlight_vote_date: + voter.highlight = True query = Vote.objects.filter(voter=voter) query = query.extra(where=['choice_id IN (%s)' \ % ",".join([str(choice.id) for choice in choices])]) diff --git a/static/styles.css b/static/styles.css index e41d670..7359392 100644 --- a/static/styles.css +++ b/static/styles.css @@ -69,6 +69,12 @@ label{ font-weight:bold; } +hr.spacer{ +clear:both; +height:0; +border:0; +} + #main{ background-color:white; border:1px solid; @@ -132,6 +138,9 @@ margin:5px; #poll_table{ overflow:auto; +text-align:center; +display:block; +float:left; } #poll{ @@ -149,6 +158,7 @@ padding:0; #poll td.simple{ border:None; +background-color:#FFF; } #poll th{ @@ -183,3 +193,12 @@ text-align:center; border:None; font-weight:bold; } + +tr.highlighted_voter td{ +background-color:grey; +color:white; +} + +#syndication{ +padding:10px; +} \ No newline at end of file diff --git a/templates/vote.html b/templates/vote.html index f3f1e1d..e000bc9 100644 --- a/templates/vote.html +++ b/templates/vote.html @@ -13,7 +13,8 @@ {% for choice in choices %}{{choice.name}}{% if choice.limit %} ({% trans "max" %} {{choice.limit}}){%endif%} {% endfor %} - {% for voter in voters %}{% ifequal current_voter_id voter.id %} + {% for voter in voters %} + {% ifequal current_voter_id voter.id %} @@ -77,7 +78,11 @@ {% endfor %} - + +
+
+ {% trans "Remain informed of poll evolution:" %} {%trans "Syndication"%} +
{% endblock %} diff --git a/urls.py b/urls.py index bda20ee..2234ab3 100644 --- a/urls.py +++ b/urls.py @@ -18,14 +18,22 @@ # See the file COPYING for details. from django.conf.urls.defaults import * +from polls.feeds import PollLatestEntries + +feeds = { + 'poll': PollLatestEntries, +} + urlpatterns = patterns('', - (r'^admin/', include('django.contrib.admin.urls')), + (r'^papillon/admin/', include('django.contrib.admin.urls')), (r'^papillon/$', 'papillon.polls.views.index'), (r'^papillon/edit/(?P\w+)/$', 'papillon.polls.views.createOrEdit'), (r'^papillon/poll/(?P\w+)/$', 'papillon.polls.views.poll'), (r'^papillon/poll/(?P\w+)/vote$', 'papillon.polls.views.poll'), + (r'^papillon/feeds/(?P.*)$', + 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), (r'^papillon/static/(?P.*)$', 'django.views.static.serve', {'document_root': 'static/'}), ) -- cgit v1.2.3