Added view permission to all data models. Added fixtures autoload.
[e_cidadania.git] / src / apps / ecidadania / debate / models.py
blob463db9b2a79d10c9367c208ee9c4785b4eb7d89e
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 """
21 This file contains all the data models for the debate module.
22 """
23 import datetime
25 from django.db import models
26 from django.contrib.auth.models import User
27 from django.utils.translation import ugettext_lazy as _
28 from django.core.exceptions import ValidationError
30 from apps.thirdparty.tagging.fields import TagField
31 from apps.thirdparty.tagging.models import Tag
32 from core.spaces.models import Space
35 class Debate(models.Model):
37 """
38 Debate object. In every space there can be unlimited debates, each one of
39 them holds all the related notes. Debates are filtered by space. Start/End
40 dates are for letting users use the debate or not.
42 .. versionadded:: 0.1b
43 """
44 title = models.CharField(_('Title'), max_length=200, unique=True)
45 description = models.TextField(_('Description'), blank=True, null=True)
46 theme = models.CharField(_('Theme'), blank=True, null=True, max_length=100)
48 space = models.ForeignKey(Space, blank=True, null=True)
49 date = models.DateTimeField(_('Date created'), auto_now_add=True)
50 date_mod = models.DateTimeField(_('Last update'), auto_now=True)
51 author = models.ForeignKey(User, blank=True, null=True)
52 start_date = models.DateField(_('Start date'))
53 end_date = models.DateField(_('End date'))
55 class Meta:
56 permissions = (
57 ('view', 'Can view the debate'),
60 def __unicode__(self):
61 return self.title
63 def is_active(self):
64 if datetime.date.today() >= self.end_date or datetime.date.today() <= self.start_date:
65 return False
66 else:
67 return True
69 @models.permalink
70 def get_absolute_url(self):
71 return ('view-debate', (), {
72 'space_url': self.space.url,
73 'debate_id': str(self.id)})
75 def clean(self):
76 if self.start_date > self.end_date:
77 raise ValidationError('The start date can not be after the end date.')
80 class Column(models.Model):
81 """
82 Debate column object. The debate table is done mixing columns and rows. The column
83 object is linked to the debate, but with no preferable order.
85 .. versionadded:: 0.1b
86 """
87 criteria = models.CharField(_('Criteria'), max_length=100, blank=True, null=True)
88 debate = models.ForeignKey(Debate, blank=True, null=True)
90 def __unicode__(self):
91 return self.criteria
94 class Row(models.Model):
95 """
96 Row object for the debate system. The row object works exactly like the
97 column. It's associated to the debate in no preferred order.
99 .. versionadded:: 0.1b
101 criteria = models.CharField(_('Criteria'), max_length=100, blank=True, null=True)
102 debate = models.ForeignKey(Debate, blank=True, null=True)
104 def __unicode__(self):
105 return self.criteria
108 class Note(models.Model):
111 The most important object in every debate, the message. It has a coordinates
112 value to determine the position of the note in its debate.
114 .. versionadded:: 0.1b
116 column = models.ForeignKey(Column, null=True, blank=True)
117 row = models.ForeignKey(Row, null=True, blank=True)
118 debate = models.ForeignKey(Debate, null=True, blank=True)
119 title = models.CharField(_('Title'), max_length=60, blank=True, null=True)
120 message = models.TextField(_('Message'), max_length=100, null=True, blank=True)
122 date = models.DateTimeField(_('Date created'), auto_now_add=True)
123 author = models.ForeignKey(User, null=True, blank=True, related_name="note_author")
124 last_mod_author = models.ForeignKey(User, null=True, blank=True, related_name="update_author")
125 last_mod = models.DateTimeField(_('Last modification time'), auto_now=True)
127 def __unicode__(self):
128 return self.message
130 class Meta:
131 permissions = (
132 ('move', 'Can move note'),