1+ from euphorie .client import utils
12from euphorie .client .navigation import getTreeData
23from plone import api
34from 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 ()
0 commit comments