From c312ce1316d390c4f4c638e028a319379ce5e708 Mon Sep 17 00:00:00 2001 From: Rogelio Mita Date: Thu, 26 Sep 2013 14:31:49 +0000 Subject: Disable "Modificar estructura" button when a poll is read_only --- 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/structure_tests.py b/webapp/polls/tests/structure_tests.py index ba30c91..c9fe0d9 100644 --- a/webapp/polls/tests/structure_tests.py +++ b/webapp/polls/tests/structure_tests.py @@ -332,6 +332,18 @@ class ReadOnlyTest(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)} -- cgit v0.9.1