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/>.
21 This file contains all the data models for the debate module.
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
):
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
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'))
57 ('view', 'Can view the debate'),
60 def __unicode__(self
):
64 if datetime
.date
.today() >= self
.end_date
or datetime
.date
.today() <= self
.start_date
:
70 def get_absolute_url(self
):
71 return ('view-debate', (), {
72 'space_url': self
.space
.url
,
73 'debate_id': str(self
.id)})
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
):
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
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
):
94 class Row(models
.Model
):
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
):
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
):
132 ('move', 'Can move note'),