def update(self): if redirectOnSurveyUpdate(self.request): return if self.request.environ["REQUEST_METHOD"] == "POST": return self._update() context = aq_inner(self.context) module = self.request.survey.restrictedTraverse( self.context.zodb_path.split("/")) self.module = module if ((IProfileQuestion.providedBy(module) and context.depth == 2) or (ICustomRisksModule.providedBy(module) and self.phase == 'actionplan')): next = FindNextQuestion(context, filter=self.question_filter) if next is None: if self.phase == 'identification': url = "%s/actionplan" % self.request.survey.absolute_url() elif self.phase == 'evaluation': url = "%s/actionplan" % self.request.survey.absolute_url() elif self.phase == 'actionplan': url = "%s/report" % self.request.survey.absolute_url() else: url = QuestionURL(self.request.survey, next, phase=self.phase) return self.request.response.redirect(url) else: return self._update()
def update(self): self.survey = survey = aq_parent(aq_inner(self.context)) question = FindFirstQuestion(filter=self.question_filter) if question is not None: self.next_url = QuestionURL(survey, question, phase="actionplan") self.tree = getTreeData(self.request, question, filter=self.question_filter, phase="actionplan") else: self.next_url = None
def _update(self): survey = self.request.survey self.title = self.context.title self.tree = getTreeData(self.request, self.context, filter=self.question_filter, phase=self.phase) previous = FindPreviousQuestion(self.context, filter=self.question_filter) if previous is None: self.previous_url = "%s/%s" % (self.request.survey.absolute_url(), self.phase) else: self.previous_url = QuestionURL(survey, previous, phase=self.phase) next = FindNextQuestion(self.context, filter=self.question_filter) if next is None: self.next_url = "%s/report" % self.request.survey.absolute_url() else: self.next_url = QuestionURL(survey, next, phase=self.phase) super(ActionPlanView, self).update()
def update(self): if redirectOnSurveyUpdate(self.request): return self.survey = survey = aq_parent(aq_inner(self.context)) question = FindFirstQuestion(filter=self.question_filter) if question is not None: self.next_url = QuestionURL(survey, question, phase="identification") self.tree = getTreeData(self.request, question) else: self.next_url = None
def save_and_continue(self, module): """ We received a POST request. Submit the form and figure out where to go next. """ context = aq_inner(self.context) reply = self.request.form if module.optional: if "skip_children" in reply: context.skip_children = reply.get("skip_children") context.postponed = False else: context.postponed = True SessionManager.session.touch() if reply["next"] == "previous": next = FindPreviousQuestion(context, filter=self.question_filter) if next is None: # We ran out of questions, step back to intro page url = "%s/identification" % self.request.survey.absolute_url() self.request.response.redirect(url) return else: if ICustomRisksModule.providedBy(module): if not context.skip_children: # The user will now be allowed to create custom # (user-defined) risks. url = "%s/customization/%d" % ( self.request.survey.absolute_url(), int(self.context.path)) return self.request.response.redirect(url) else: # We ran out of questions, proceed to the evaluation url = "%s/actionplan" % self.request.survey.absolute_url() return self.request.response.redirect(url) next = FindNextQuestion(context, filter=self.question_filter) if next is None: # We ran out of questions, proceed to the evaluation url = "%s/actionplan" % self.request.survey.absolute_url() return self.request.response.redirect(url) url = QuestionURL(self.request.survey, next, phase="identification") self.request.response.redirect(url)
def update(self): if redirectOnSurveyUpdate(self.request): return context = aq_inner(self.context) module = self.request.survey.restrictedTraverse( context.zodb_path.split("/")) if self.request.environ["REQUEST_METHOD"] == "POST": self.save_and_continue(module) else: if IProfileQuestion.providedBy(module) and context.depth == 2: next = FindNextQuestion(context, filter=self.question_filter) if next is None: url = "%s/actionplan" % self.request.survey.absolute_url() else: url = QuestionURL(self.request.survey, next, phase=self.phase) return self.request.response.redirect(url) elif ICustomRisksModule.providedBy(module) \ and not self.context.skip_children \ and len(self.get_custom_risks()): url = "%s/customization/%d" % ( self.request.survey.absolute_url(), int(self.context.path)) return self.request.response.redirect(url) self.tree = getTreeData(self.request, context, filter=model.NO_CUSTOM_RISKS_FILTER) self.title = module.title self.module = module number_files = 0 for i in range(1, 5): number_files += getattr(self.module, 'file{0}'.format(i), None) and 1 or 0 self.has_files = number_files > 0 self.next_is_actionplan = not FindNextQuestion( context, filter=self.question_filter) super(IdentificationView, self).update()
def update(self): if redirectOnSurveyUpdate(self.request): return self.risk = self.request.survey.restrictedTraverse( self.context.zodb_path.split("/")) appconfig = getUtility(IAppConfig) settings = appconfig.get('euphorie') self.use_existing_measures = settings.get('use_existing_measures', False) if self.request.environ["REQUEST_METHOD"] == "POST": reply = self.request.form answer = reply.get("answer") self.context.comment = reply.get("comment") if self.use_existing_measures: measures = self.get_existing_measures() new_measures = [] for i, entry in enumerate(measures): on = int(bool(reply.get('measure-{}'.format(i)))) entry[0] = on measures[i] = entry if on: new_measures.append([1, entry[1]]) for k, val in reply.items(): if k.startswith('new-measure') and val.strip() != '': new_measures.append([1, val]) self.context.existing_measures = dumps(new_measures) self.context.postponed = (answer == "postponed") if self.context.postponed: self.context.identification = None else: self.context.identification = answer if self.risk.type in ('top5', 'policy'): self.context.priority = 'high' elif self.risk.evaluation_method == 'calculated': self.calculatePriority(self.risk, reply) elif self.risk.evaluation_method == "direct": self.context.priority = reply.get("priority") SessionManager.session.touch() if reply["next"] == "previous": next = FindPreviousQuestion(self.context, filter=self.question_filter) if next is None: # We ran out of questions, step back to intro page url = "%s/identification" % \ self.request.survey.absolute_url() self.request.response.redirect(url) return else: next = FindNextQuestion(self.context, filter=self.question_filter) if next is None: # We ran out of questions, proceed to the action plan url = "%s/actionplan" % self.request.survey.absolute_url() self.request.response.redirect(url) return url = QuestionURL(self.request.survey, next, phase="identification") self.request.response.redirect(url) else: self.tree = getTreeData(self.request, self.context) self.title = self.context.parent.title self.show_info = self.risk.image or \ HasText(self.risk.description) or \ HasText(self.risk.legal_reference) number_images = getattr(self.risk, 'image', None) and 1 or 0 if number_images: for i in range(2, 5): number_images += getattr(self.risk, 'image{0}'.format(i), None) and 1 or 0 self.has_images = number_images > 0 self.number_images = number_images self.image_class = IMAGE_CLASS[number_images] number_files = 0 for i in range(1, 5): number_files += getattr(self.risk, 'file{0}'.format(i), None) and 1 or 0 self.has_files = number_files > 0 self.risk_number = self.context.number ploneview = getMultiAdapter((self.context, self.request), name="plone") stripped_description = StripMarkup(self.risk.description) if len(stripped_description) > self.DESCRIPTION_CROP_LENGTH: self.description_intro = ploneview.cropText( stripped_description, self.DESCRIPTION_CROP_LENGTH) else: self.description_intro = "" self.description_probability = _( u"help_default_probability", default=u"Indicate how " "likely occurence of this risk is in a normal situation.") self.description_frequency = _( u"help_default_frequency", default=u"Indicate how often this " u"risk occurs in a normal situation.") self.description_severity = _(u"help_default_severity", default=u"Indicate the " "severity if this risk occurs.") self.title_extra = '' self.show_existing_measures = False if self.use_existing_measures: measures = self.risk.existing_measures or "" # Only show the form to select and add existing measures if # at least one measure was defined in the CMS if len(measures): self.show_existing_measures = True self.title_extra = _( "Are the measures that are selected above sufficient?") if not self.context.existing_measures: self.context.existing_measures = dumps([ (1, text) for text in measures.splitlines() ]) if getattr(self.request.survey, 'enable_custom_evaluation_descriptions', False): if self.request.survey.evaluation_algorithm != 'french': custom_dp = getattr(self.request.survey, 'description_probability', '') or '' self.description_probability = custom_dp.strip( ) or self.description_probability custom_df = getattr(self.request.survey, 'description_frequency', '') or '' self.description_frequency = custom_df.strip( ) or self.description_frequency custom_ds = getattr(self.request.survey, 'description_severity', '') or '' self.description_severity = custom_ds.strip( ) or self.description_severity # Italian special if IItalyIdentificationPhaseSkinLayer.providedBy(self.request): self.skip_evaluation = True else: self.skip_evaluation = False super(IdentificationView, self).update()
def update(self): if redirectOnSurveyUpdate(self.request): return context = aq_inner(self.context) appconfig = getUtility(IAppConfig) settings = appconfig.get('euphorie') self.use_existing_measures = settings.get('use_existing_measures', False) self.next_is_report = False # already compute "next" here, so that we can know in the template # if the next step might be the report phase, in which case we # need to switch off the sidebar next = FindNextQuestion(context, filter=self.question_filter) if next is None: # We ran out of questions, proceed to the report url = "%s/report" % self.request.survey.absolute_url() self.next_is_report = True else: url = QuestionURL(self.request.survey, next, phase="actionplan") if self.request.environ["REQUEST_METHOD"] == "POST": reply = self.request.form session = Session() context.comment = reply.get("comment") context.priority = reply.get("priority") new_plans = self.extract_plans_from_request() for plan in context.action_plans: session.delete(plan) context.action_plans.extend(new_plans) SessionManager.session.touch() if reply["next"] == "previous": next = FindPreviousQuestion(context, filter=self.question_filter) if next is None: # We ran out of questions, step back to intro page url = "%s/evaluation" % self.request.survey.absolute_url() else: url = QuestionURL(self.request.survey, next, phase="actionplan") return self.request.response.redirect(url) else: self.data = context if len(context.action_plans) == 0: self.data.empty_action_plan = [model.ActionPlan()] self.title = context.parent.title self.tree = getTreeData(self.request, context, filter=self.question_filter, phase="actionplan") if self.context.is_custom_risk: self.risk = self.context self.description_intro = u"" self.risk.description = u"" number_images = 0 else: self.risk = self.request.survey.restrictedTraverse( context.zodb_path.split("/")) number_images = getattr(self.risk, 'image', None) and 1 or 0 if number_images: for i in range(2, 5): number_images += getattr(self.risk, 'image{0}'.format(i), None) and 1 or 0 ploneview = getMultiAdapter((self.context, self.request), name="plone") stripped_description = StripMarkup(self.risk.description) if len(stripped_description) > self.DESCRIPTION_CROP_LENGTH: self.description_intro = ploneview.cropText( stripped_description, self.DESCRIPTION_CROP_LENGTH) else: self.description_intro = "" self.solutions = [ solution for solution in self.risk.values() if ISolution.providedBy(solution) ] self.number_images = number_images self.has_images = number_images > 0 self.image_class = IMAGE_CLASS[number_images] self.risk_number = self.context.number lang = getattr(self.request, 'LANGUAGE', 'en') if "-" in lang: elems = lang.split("-") lang = "{0}_{1}".format(elems[0], elems[1].upper()) self.delete_confirmation = translate(_( u"Are you sure you want to delete this measure? This action can " u"not be reverted."), target_language=lang) self.override_confirmation = translate(_( u"The current text in the fields 'Action plan', 'Prevention plan' and " u"'Requirements' of this measure will be overwritten. This action cannot be " u"reverted. Are you sure you want to continue?"), target_language=lang) self.message_date_before = translate(_( u"error_validation_before_end_date", default=u"This date must be on or before the end date."), target_language=lang) self.message_date_after = translate(_( u"error_validation_after_start_date", default=u"This date must be on or after the start date."), target_language=lang) self.message_positive_number = translate(_( u"error_validation_positive_whole_number", default=u"This value must be a positive whole number."), target_language=lang) super(ActionPlanView, self).update()