Added django badge
[e_cidadania.git] / src / apps / ecidadania / debate / models.py
blob1cabbc22f8f534d1ed8a08c10eec742e81716d35
1 # -*- coding: utf-8 -*-
3 # Copyright (c) 2013 Clione Software
4 # Copyright (c) 2010-2013 Cidadania S. Coop. Galega
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 """
19 This file contains all the data models for the debate module.
20 """
21 import datetime
23 from django.db import models
24 from django.contrib.auth.models import User
25 from django.utils.translation import ugettext_lazy as _
26 from django.core.exceptions import ValidationError
28 from apps.thirdparty.tagging.fields import TagField
29 from apps.thirdparty.tagging.models import Tag
30 from core.spaces.models import Space
33 class Debate(models.Model):
35 """
36 Debate object. In every space there can be unlimited debates, each one of
37 them holds all the related notes. Debates are filtered by space. Start/End
38 dates are for letting users use the debate or not.
40 .. versionadded:: 0.1b
41 """
42 title = models.CharField(_('Title'), max_length=200, unique=True)
43 description = models.TextField(_('Description'), blank=True, null=True)
44 theme = models.CharField(_('Theme'), blank=True, null=True, max_length=100)
46 space = models.ForeignKey(Space, blank=True, null=True)
47 date = models.DateTimeField(_('Date created'), auto_now_add=True)
48 date_mod = models.DateTimeField(_('Last update'), auto_now=True)
49 author = models.ForeignKey(User, blank=True, null=True)
50 start_date = models.DateField(_('Start date'))
51 end_date = models.DateField(_('End date'))
52 private = models.BooleanField(_('Private'), help_text=_('Set the debate as private so only the accepted users can participate in it.'))
54 class Meta:
55 permissions = (
56 ('view_debate', 'Can view the debate'),
57 ('admin_debate', 'Can administrate the debate'),
58 ('mod_debate', 'Can moderate the debate'),
61 def __unicode__(self):
62 return self.title
64 def is_active(self):
65 if datetime.date.today() >= self.end_date or datetime.date.today() <= self.start_date:
66 return False
67 else:
68 return True
70 @models.permalink
71 def get_absolute_url(self):
72 return ('view-debate', (), {
73 'space_url': self.space.url,
74 'debate_id': str(self.id)})
76 def clean(self):
77 if self.start_date > self.end_date:
78 raise ValidationError('The start date can not be after the end date.')
81 class Column(models.Model):
82 """
83 Debate column object. The debate table is done mixing columns and rows. The column
84 object is linked to the debate, but with no preferable order.
86 .. versionadded:: 0.1b
87 """
88 criteria = models.CharField(_('Criteria'), max_length=100, blank=True, null=True)
89 debate = models.ForeignKey(Debate, blank=True, null=True)
91 def __unicode__(self):
92 return self.criteria
95 class Row(models.Model):
96 """
97 Row object for the debate system. The row object works exactly like the
98 column. It's associated to the debate in no preferred order.
100 .. versionadded:: 0.1b
102 criteria = models.CharField(_('Criteria'), max_length=100, blank=True, null=True)
103 debate = models.ForeignKey(Debate, blank=True, null=True)
105 def __unicode__(self):
106 return self.criteria
109 class Note(models.Model):
112 The most important object in every debate, the message. It has a coordinates
113 value to determine the position of the note in its debate.
115 .. versionadded:: 0.1b
117 column = models.ForeignKey(Column, null=True, blank=True)
118 row = models.ForeignKey(Row, null=True, blank=True)
119 debate = models.ForeignKey(Debate, null=True, blank=True)
120 title = models.CharField(_('Title'), max_length=60, blank=True, null=True)
121 message = models.TextField(_('Message'), max_length=100, null=True, blank=True)
123 date = models.DateTimeField(_('Date created'), auto_now_add=True)
124 author = models.ForeignKey(User, null=True, blank=True, related_name="note_author")
125 last_mod_author = models.ForeignKey(User, null=True, blank=True, related_name="update_author")
126 last_mod = models.DateTimeField(_('Last modification time'), auto_now=True)
128 def __unicode__(self):
129 return self.message
131 class Meta:
132 permissions = (
133 ('move', 'Can move note'),