summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoretienne2008-12-03 13:35:22 +0000
committeretienne2008-12-03 13:35:22 +0000
commitc1179cc913cce18c7d5a317da15363c3118ca1d7 (patch)
tree8795a1f27dc911aae53c9c8d6b857b733a69935a
parent7ecbc6bf2ba614afee40d344d9191abd5f371db4 (diff)
First version of syndication. Change on the css
-rw-r--r--polls/models.py5
-rw-r--r--polls/views.py19
-rw-r--r--static/styles.css19
-rw-r--r--templates/vote.html9
-rw-r--r--urls.py10
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 @@
<td class='simple'></td>
{% for choice in choices %}<th>{{choice.name}}{% if choice.limit %} ({% trans "max" %} {{choice.limit}}){%endif%}</th>
{% endfor %}</tr>
- {% for voter in voters %}<tr>{% ifequal current_voter_id voter.id %}
+ {% for voter in voters %}<tr{% if voter.highlight %} class='highlighted_voter'{% endif %}>
+ {% ifequal current_voter_id voter.id %}
<input type='hidden' name='voter' value='{{voter.id}}'/>
<td class='simple'></td>
<td><input type='text' name='author_name' value='{{voter.user.name}}'/></td>
@@ -77,7 +78,11 @@
{% endfor %}
</tr>
</table>
- </div>
<input type='submit' value='{%if current_voter_id%}{% trans "Edit" %}{%else%}{% trans "Participate" %}{%endif%}'/>
+ </div>
+ <hr class='spacer'/>
</form>
+ <div id='syndication'>
+ {% trans "Remain informed of poll evolution:" %} <a href="/papillon/feeds/poll/{{poll_base_url}}/">{%trans "Syndication"%}</a>
+ </div>
{% 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<admin_url>\w+)/$',
'papillon.polls.views.createOrEdit'),
(r'^papillon/poll/(?P<poll_url>\w+)/$', 'papillon.polls.views.poll'),
(r'^papillon/poll/(?P<poll_url>\w+)/vote$', 'papillon.polls.views.poll'),
+ (r'^papillon/feeds/(?P<url>.*)$',
+ 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
(r'^papillon/static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': 'static/'}),
)