Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-09-26 14:36:46 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-09-26 14:36:46 (GMT)
commitdcda2d37e96c38f435aa30839cbf8806a4c26900 (patch)
tree4d833dc14839d2d180d03efef3fd1be7b7e7ebef
parent8767b61a5686a05292942c764f1eb16a499878ab (diff)
parentc312ce1316d390c4f4c638e028a319379ce5e708 (diff)
Read only structure new condition: poll closed or poll with result
-rw-r--r--webapp/polls/models.py2
-rw-r--r--webapp/polls/tests/poll_tests.py1
-rw-r--r--webapp/polls/tests/result_tests.py16
-rw-r--r--webapp/polls/tests/structure_tests.py20
-rw-r--r--webapp/polls/views.py3
5 files changed, 31 insertions, 11 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index be917cc..9402c94 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -1323,7 +1323,7 @@ class Structure(AbstractObject, ComponentStructure):
def is_read_only(self):
"""Tells if the structure can be modified."""
poll = self.poll
- return poll.has_result()
+ return not poll.is_open() or poll.has_result()
class NodePollResult(object):
diff --git a/webapp/polls/tests/poll_tests.py b/webapp/polls/tests/poll_tests.py
index 19c36c1..0b3a168 100644
--- a/webapp/polls/tests/poll_tests.py
+++ b/webapp/polls/tests/poll_tests.py
@@ -188,7 +188,6 @@ class PollTests(MongoTestCase):
def test_clone(self):
poll = Poll(data={'name': 'name'})
- poll.status = Poll.CLOSED
poll_id = poll.save()
poll = Poll.get(poll_id)
diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py
index 57ae49a..0936cf0 100644
--- a/webapp/polls/tests/result_tests.py
+++ b/webapp/polls/tests/result_tests.py
@@ -96,8 +96,7 @@ class PollResultTests(MongoTestCase):
poll_data = {
"name": "test",
- "pollsters": [pollster],
- "status": Poll.CLOSED
+ "pollsters": [pollster]
}
structure_data = {
@@ -325,10 +324,7 @@ class CsvNoRepitePesoParaOpcionesConElMismoTextDescriptivo(MongoTestCase):
"""
def setUp(self):
- poll_data = {
- "name": "test",
- "status": Poll.CLOSED
- }
+ poll_data = {"name": "test"}
question_name = "repite nombre pregunta"
structure_data = {
@@ -397,10 +393,14 @@ class CsvNoRepitePesoParaOpcionesConElMismoTextDescriptivo(MongoTestCase):
poll = Poll(data=poll_data)
poll_id = poll.save()
- self.poll = Poll.get(poll_id)
- structure = Structure(data=structure_data, poll=self.poll)
+ poll = Poll.get(poll_id)
+ structure = Structure(data=structure_data, poll=poll)
structure.save()
+ poll.status = Poll.CLOSED
+ poll_id = poll.save()
+ self.poll = Poll.get(poll_id)
+
def test_get_csv_header_with_order(self):
poll = self.poll
diff --git a/webapp/polls/tests/structure_tests.py b/webapp/polls/tests/structure_tests.py
index aeb8702..c9fe0d9 100644
--- a/webapp/polls/tests/structure_tests.py
+++ b/webapp/polls/tests/structure_tests.py
@@ -314,6 +314,14 @@ class StructureTests(MongoTestCase):
def test_it_should_respond_to_ready_only_msg(self):
self.assertTrue(hasattr(Structure, 'READ_ONLY_MSG'))
+
+class ReadOnlyTest(MongoTestCase):
+
+ def setUp(self):
+ poll = Poll({"name": "poll name"})
+ poll_id = poll.save()
+ self.poll = poll.get(poll_id)
+
def test_it_should_be_read_only_when_poll_has_results(self):
poll = self.poll
structure = Structure(data={}, poll=poll)
@@ -324,6 +332,18 @@ class StructureTests(MongoTestCase):
self.assertTrue(poll.has_result())
self.assertTrue(structure.is_read_only())
+ def test_read_only_when_poll_is_closed_and_has_not_results(self):
+ poll = self.poll
+ poll.status = Poll.CLOSED
+ poll_id = poll.save()
+ poll = poll.get(poll_id)
+
+ structure = Structure(data={}, poll=poll)
+ self.assertFalse(poll.has_result())
+ self.assertFalse(poll.is_open())
+
+ self.assertTrue(structure.is_read_only())
+
class UploadOptionImagesTest(MongoTestCase):
diff --git a/webapp/polls/views.py b/webapp/polls/views.py
index cca83da..c19eac1 100644
--- a/webapp/polls/views.py
+++ b/webapp/polls/views.py
@@ -168,7 +168,8 @@ class PollListView(ListView):
),
},
'action_structure_builder': {
- 'disabled': "disabled" if not poll.is_open() else "",
+ 'disabled': ("disabled" if
+ poll.structure.is_read_only() else ""),
'url': reverse(
'sociologist:structure.builder',
kwargs={'poll_id': str(poll.id)}