Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp/polls/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/polls/models.py')
-rw-r--r--webapp/polls/models.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index 0090164..9402c94 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -10,9 +10,7 @@ import copy
import warnings
import glob
import errno
-
from distutils.dir_util import copy_tree
-from exceptions import ValidationError, UniqueNameError
from bson import ObjectId, DBRef
from datetime import datetime
@@ -23,8 +21,8 @@ from django.core.exceptions import ValidationError as DjangoValidationError
from utils.mongo_connection import get_db
from utils.mongo_document import Document
from utils.strings import multiple_replace
-
from pollster.models import Pollster
+from polls.exceptions import ReadOnly, ValidationError
def is_image_file(value):
@@ -70,7 +68,6 @@ class AbstracErrorObject(object):
class Poll(Document, AbstracErrorObject):
collection_name = 'polls'
- UniqueNameError = UniqueNameError
OPEN = "Abierta"
CLOSED = "Cerrada"
@@ -1001,8 +998,9 @@ class Group(AbstractObject, ComponentStructure):
class Structure(AbstractObject, ComponentStructure):
+ """Class that handles the structure of a poll.
- """
+ Example of data_structure:
{
'groups': {
'0': {
@@ -1022,6 +1020,8 @@ class Structure(AbstractObject, ComponentStructure):
}
}
"""
+ READ_ONLY_MSG = ('No puede modificar la estructura'
+ ' de una encuesta con resultados.')
def __init__(self, data={}, poll=None, *args, **kwargs):
super(Structure, self).__init__(poll, *args, **kwargs)
@@ -1168,6 +1168,7 @@ class Structure(AbstractObject, ComponentStructure):
return data
def save(self):
+ """Save structure to database. Returns structure's ID."""
structure_id = None
self.validate()
@@ -1177,6 +1178,8 @@ class Structure(AbstractObject, ComponentStructure):
# Prepare dbref to poll object
if not self.poll:
raise ValidationError("Need a parent poll.")
+ elif self.is_read_only():
+ raise ReadOnly(Structure.READ_ONLY_MSG)
else:
dbref = DBRef(Poll.collection_name, ObjectId(self.poll.id))
_dict.update({'poll': dbref})
@@ -1317,6 +1320,11 @@ class Structure(AbstractObject, ComponentStructure):
# TODO: LOG!
pass
+ def is_read_only(self):
+ """Tells if the structure can be modified."""
+ poll = self.poll
+ return not poll.is_open() or poll.has_result()
+
class NodePollResult(object):