Skip to content

Commit 5aa9434

Browse files
committed
Do some checks and housekeeping when choice identification view is called
1 parent b44bb4f commit 5aa9434

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/euphorie/client/browser/choice.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from euphorie.client import utils
12
from euphorie.client.navigation import getTreeData
23
from plone import api
34
from plone.memoize.instance import memoize
@@ -14,6 +15,18 @@ class IdentificationView(BrowserView):
1415
def webhelpers(self):
1516
return api.content.get_view("webhelpers", self.context.aq_parent, self.request)
1617

18+
def check_render_condition(self):
19+
# Render the page only if the user can inspection rights,
20+
# otherwise redirect to the start page of the session.
21+
if not self.webhelpers.can_inspect_session:
22+
return self.request.response.redirect(
23+
"{session_url}/@@start".format(
24+
session_url=self.webhelpers.traversed_session.absolute_url()
25+
)
26+
)
27+
if self.webhelpers.redirectOnSurveyUpdate():
28+
return
29+
1730
@property
1831
@memoize
1932
def navigation(self):
@@ -23,6 +36,12 @@ def navigation(self):
2336
def tree(self):
2437
return getTreeData(self.request, self.context)
2538

39+
@property
40+
@memoize
41+
def survey(self):
42+
"""This is the survey dexterity object."""
43+
return self.webhelpers._survey
44+
2645
@property
2746
@memoize
2847
def choice(self):
@@ -45,7 +64,7 @@ def set_answer_data(self, reply):
4564
# self.webhelpers.traversed_session.restrictedTraverse(path)
4665
# except KeyError:
4766
# answer.remove(path)
48-
self.context.set_options_by_zodb_path(answer)
67+
return self.context.set_options_by_zodb_path(answer)
4968

5069
def __call__(self):
5170
# Render the page only if the user has inspection rights,
@@ -54,8 +73,23 @@ def __call__(self):
5473
return self.request.response.redirect(
5574
self.context.aq_parent.absolute_url() + "/@@start"
5675
)
76+
self.check_render_condition()
77+
78+
utils.setLanguage(self.request, self.survey, self.survey.language)
79+
5780
if self.request.method == "POST":
5881
reply = self.request.form
59-
self.set_answer_data(reply)
82+
if not self.webhelpers.can_edit_session:
83+
return self.navigation.proceed_to_next(reply)
84+
_next = self._get_next(reply)
85+
# Don't persist anything if the user skipped the question
86+
if _next == "skip":
87+
return self.navigation.proceed_to_next(reply)
88+
89+
changed = self.set_answer_data(reply)
90+
91+
if changed:
92+
self.session.touch()
93+
6094
return self.navigation.proceed_to_next(reply)
6195
return self.index()

src/euphorie/client/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,15 +1539,19 @@ def is_visible(self):
15391539

15401540
def set_options_by_zodb_path(self, paths):
15411541
current = [option.zodb_path for option in self.options]
1542+
changed = False
15421543
for option in self.options:
15431544
if option.zodb_path not in paths:
15441545
self.options.remove(option)
15451546
Session.delete(option)
1547+
changed = True
15461548
for path in paths:
15471549
if path not in current:
15481550
option = Option(choice=self, zodb_path=path)
15491551
Session.add(option)
15501552
self.options.append(option)
1553+
changed = True
1554+
return changed
15511555

15521556

15531557
class Option(BaseObject):

0 commit comments

Comments
 (0)