fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix for unclickable cites in admin.
[wolnelektury.git]
/
apps
/
polls
/
models.py
diff --git
a/apps/polls/models.py
b/apps/polls/models.py
index
16713e4
..
8e35668
100644
(file)
--- a/
apps/polls/models.py
+++ b/
apps/polls/models.py
@@
-15,50
+15,50
@@
class Poll(models.Model):
question = models.TextField(_('question'))
slug = models.SlugField(_('slug'))
question = models.TextField(_('question'))
slug = models.SlugField(_('slug'))
- open = models.BooleanField(_('open'), default
=
False)
-
+ open = models.BooleanField(_('open'), default
=
False)
+
class Meta:
verbose_name = _('Poll')
verbose_name_plural = _('Polls')
class Meta:
verbose_name = _('Poll')
verbose_name_plural = _('Polls')
-
+
def clean(self):
def clean(self):
- if self.open and Poll.objects.exclude(pk
= self.pk).filter(slug =
self.slug).exists():
+ if self.open and Poll.objects.exclude(pk
=self.pk).filter(slug=
self.slug).exists():
raise ValidationError(_('Slug of an open poll needs to be unique'))
return super(Poll, self).clean()
raise ValidationError(_('Slug of an open poll needs to be unique'))
return super(Poll, self).clean()
-
+
def __unicode__(self):
return self.question[:100] + ' (' + self.slug + ')'
def __unicode__(self):
return self.question[:100] + ' (' + self.slug + ')'
-
+
def get_absolute_url(self):
def get_absolute_url(self):
- return reverse('poll', args
=
[self.slug])
-
+ return reverse('poll', args
=
[self.slug])
+
@property
def vote_count(self):
return self.items.all().aggregate(models.Sum('vote_count'))['vote_count__sum']
@property
def vote_count(self):
return self.items.all().aggregate(models.Sum('vote_count'))['vote_count__sum']
-
+
def voted(self, session):
def voted(self, session):
- return self.id in session.get(USED_POLLS_KEY, set())
+ return self.id in session.get(USED_POLLS_KEY, [])
+
-
class PollItem(models.Model):
class PollItem(models.Model):
-
- poll = models.ForeignKey(Poll, related_name
=
'items')
+
+ poll = models.ForeignKey(Poll, related_name
=
'items')
content = models.TextField(_('content'))
content = models.TextField(_('content'))
- vote_count = models.IntegerField(_('vote count'), default
=
0)
-
+ vote_count = models.IntegerField(_('vote count'), default
=
0)
+
class Meta:
verbose_name = _('vote item')
verbose_name_plural = _('vote items')
class Meta:
verbose_name = _('vote item')
verbose_name_plural = _('vote items')
-
\r
+
\r
def __unicode__(self):
return self.content + ' @ ' + unicode(self.poll)
def __unicode__(self):
return self.content + ' @ ' + unicode(self.poll)
-
+
@property
def vote_ratio(self):
return (float(self.vote_count) / self.poll.vote_count) * 100 if self.poll.vote_count else 0
@property
def vote_ratio(self):
return (float(self.vote_count) / self.poll.vote_count) * 100 if self.poll.vote_count else 0
-
+
def vote(self, session):
self.vote_count = self.vote_count + 1
self.save()
def vote(self, session):
self.vote_count = self.vote_count + 1
self.save()
- session.setdefault(USED_POLLS_KEY,
set()).ad
d(self.poll.id)
+ session.setdefault(USED_POLLS_KEY,
[]).appen
d(self.poll.id)
session.save()
session.save()