Minor fixes
[e_cidadania.git] / src / apps / ecidadania / voting / models.py
blobee82ca1d61d4500e1f7da5104249796532e1eaad
1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2010-2012 Cidadania S. Coop. Galega
5 # This file is part of e-cidadania.
7 # e-cidadania is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # e-cidadania is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with e-cidadania. If not, see <http://www.gnu.org/licenses/>.
20 from django.db import models
21 from django.utils.translation import ugettext_lazy as _
22 from django.contrib.auth.models import User
24 from apps.thirdparty.tagging.fields import TagField
25 from apps.thirdparty.tagging.models import Tag
26 from core.spaces.models import Space
27 from apps.ecidadania.proposals.models import *
30 PONDERATIONS = (
31 ('users', _('Users')),
32 ('fixed', _('Fixed')),
33 ('none', _('No ponderation'))
37 class Poll(models.Model):
39 """
40 Model of a new Poll
41 """
43 question = models.CharField(_('Question'), max_length=200,
44 help_text=_('Max: 200 characters'))
45 pub_date = models.DateTimeField(_('Date'), auto_now_add=True)
46 poll_lastup = models.DateTimeField(_('Last update'), auto_now=True)
47 author = models.ForeignKey(User, verbose_name=_('Author'), blank=True,
48 null=True, help_text=_('Change the user that will figure as the author'))
49 space = models.ForeignKey(Space, verbose_name=_('Publish in'), blank=True,
50 null=True, help_text=_('If you want to post to the index leave this \
51 blank'))
52 poll_tags = TagField(help_text=_('Insert here relevant words related with \
53 the poll'))
55 def __unicode__(self):
56 return self.question
58 def set_tags(self, tags):
59 Tag.objects.update_tags(self, tags)
61 def get_tags(self, tags):
62 return Tag.objects.get_for_object(self)
64 @models.permalink
65 def get_absolute_url(self):
66 if self.space is not None:
67 return ('view-polls', (), {
68 'space_url': self.space.url,
69 'poll_id': str(self.id)})
70 else:
71 return ('view-polls', (), {
72 'poll_id': str(self.id)})
75 class Choice(models.Model):
76 poll = models.ForeignKey(Poll)
77 choice_text = models.CharField(_('Choice'), max_length=200, blank=True, null=True, help_text=_('Enter choice to be voted upon'))
78 votes = models.IntegerField(blank=True, null=True, default='0')
80 @models.permalink
81 def get_absolute_url(self):
82 if self.space is not None:
83 return ('view-polls', (), {
84 'space_url': self.space.url,
85 'poll_id': str(self.id)})
86 else:
87 return ('view-polls', (), {
88 'poll_id': str(self.id)})
91 class Voting(models.Model):
92 title = models.CharField(_('Title'), max_length=200, unique=True)
93 description = models.TextField(_('Description'), blank=True, null=True)
95 space = models.ForeignKey(Space, blank=True, null=True)
96 date = models.DateTimeField(_('Date created'), auto_now_add=True)
97 date_mod = models.DateTimeField(_('Last update'), auto_now=True)
98 author = models.ForeignKey(User, blank=True, null=True)
99 start_date = models.DateField(_('Start date'), blank=True, null=True)
100 end_date = models.DateField(_('End date'), blank=True, null=True)
101 ponderation = models.CharField(_('Ponderation'), null=True, blank=True,
102 choices=PONDERATIONS)
104 proposalsets = models.ManyToManyField(ProposalSet, blank=True, null=True)
106 proposals = models.ManyToManyField(Proposal, blank = True, null=True, limit_choices_to = {'proposalset__isnull': True})
108 @models.permalink
109 def get_absolute_url(self):
110 if self.space is not None:
111 return ('view-votings', (), {
112 'space_url': self.space.url,
113 'voting_id': str(self.id)})
114 else:
115 return ('view-votings', (), {
116 'voting_id': str(self.id)})