示例#1
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        context = aq_inner(self.context)
        survey = self.request.survey
        self.module = survey.restrictedTraverse(self.context.zodb_path.split("/"))
        self.title = context.title
        self.tree = getTreeData(
            self.request, self.context, phase="identification",
            filter=model.NO_CUSTOM_RISKS_FILTER)

        lang = getattr(self.request, 'LANGUAGE', 'en')
        if "-" in lang:
            elems = lang.split("-")
            lang = "{0}_{1}".format(elems[0], elems[1].upper())
        self.message_required = translate(_(
            u"message_field_required", default=u"Please fill out this field."),
            target_language=lang)

        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            if reply.get("next") == "next":
                self.add_custom_risks(reply)
                url = "%s/actionplan" % self.request.survey.absolute_url()
                return self.request.response.redirect(url)

        return super(CustomizationView, self).update()
示例#2
0
    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()
示例#3
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        context = aq_inner(self.context)
        survey = self.request.survey
        self.module = survey.restrictedTraverse(
            self.context.zodb_path.split("/"))
        self.title = context.title
        self.tree = getTreeData(self.request,
                                self.context,
                                phase="identification",
                                filter=model.NO_CUSTOM_RISKS_FILTER)

        lang = getattr(self.request, 'LANGUAGE', 'en')
        if "-" in lang:
            elems = lang.split("-")
            lang = "{0}_{1}".format(elems[0], elems[1].upper())
        self.message_required = translate(_(
            u"message_field_required", default=u"Please fill out this field."),
                                          target_language=lang)

        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            if reply.get("next") == "next":
                self.add_custom_risks(reply)
                url = "%s/actionplan" % self.request.survey.absolute_url()
                return self.request.response.redirect(url)

        return super(CustomizationView, self).update()
示例#4
0
    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()
示例#5
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        survey = self.request.survey
        self.module = survey.restrictedTraverse(
                self.context.zodb_path.split("/"))
        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/actionplan" % \
                    self.request.survey.absolute_url()
        else:
            self.next_url = QuestionURL(survey, next, phase=self.phase)
        super(EvaluationView, self).update()
示例#6
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        self.session = SessionManager.session
        if self.session.company is None:
            self.session.company = model.Company()
        self.nodes = self.getNodes()
示例#7
0
    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="actionplan")
        else:
            self.next_url = None
示例#8
0
 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
示例#9
0
 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
示例#10
0
    def render(self):
        survey = aq_inner(self.context)
        dbsession = SessionManager.session
        if redirectOnSurveyUpdate(self.request):
            return

        question = FindFirstQuestion(dbsession=dbsession)
        if question is None:
            # No tree generated, so start over
            self.request.response.redirect("%s/start" % survey.absolute_url())
        else:
            self.request.response.redirect(
                    QuestionURL(survey, question, phase="identification"))
示例#11
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            answer = reply.get("answer")
            self.context.postponed = (answer == "postponed")
            if self.context.postponed:
                self.context.identification = None
            else:
                self.context.identification = answer
            self.context.comment = reply.get("comment")
            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 evaluation
                    url = "%s/evaluation" % 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.risk = risk = self.request.survey.restrictedTraverse(
                self.context.zodb_path.split("/"))
            self.tree = getTreeData(self.request, self.context)
            self.title = self.context.parent.title
            self.show_info = risk.image or \
                HasText(risk.description) or \
                HasText(risk.legal_reference)

            super(IdentificationView, self).update()
示例#12
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        risk = self.request.survey.restrictedTraverse(
            self.context.zodb_path.split("/"))

        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            self.context.comment = reply.get("comment")
            if risk.evaluation_method == "direct":
                self.context.priority = reply.get("priority")
            elif risk.evaluation_method == 'calculated':
                self.calculatePriority(risk, reply)

            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/evaluation" % 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="evaluation")
            self.request.response.redirect(url)
        else:
            self.risk = risk
            self.title = self.context.parent.title
            self.tree = getTreeData(
                self.request, self.context,
                filter=self.question_filter, phase="evaluation")
            super(EvaluationView, self).update()
示例#13
0
    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":
            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:
                next = FindNextQuestion(context, filter=self.question_filter)
                if next is None:
                    # We ran out of questions, proceed to the evaluation
                    url = "%s/evaluation" % 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, context)
            self.title = context.title
            self.module = module

            super(IdentificationView, self).update()
示例#14
0
    def render(self):
        survey = aq_inner(self.context)
        dbsession = SessionManager.session
        if redirectOnSurveyUpdate(self.request):
            return

        question = FindFirstQuestion(dbsession=dbsession)
        if question is None:
            # No tree generated, so start over
            self.request.response.redirect("%s/start?initial_view=1" % survey.absolute_url())
        else:
            # Redirect to the start page of the Identification phase.
            # We do this to ensure the screen with the tool name gets shown.
            # If we jump directly to the first question, the user does not
            # see the tool name.
            # This is especially relevant since the osc-header now displays the
            # user-given session name.
            self.request.response.redirect(
                "{0}/{1}?initial_view=1".format(survey.absolute_url(), "identification"))
示例#15
0
    def render(self):
        survey = aq_inner(self.context)
        dbsession = SessionManager.session
        if redirectOnSurveyUpdate(self.request):
            return

        question = FindFirstQuestion(dbsession=dbsession)
        if question is None:
            # No tree generated, so start over
            self.request.response.redirect("%s/start?initial_view=1" %
                                           survey.absolute_url())
        else:
            # Redirect to the start page of the Identification phase.
            # We do this to ensure the screen with the tool name gets shown.
            # If we jump directly to the first question, the user does not
            # see the tool name.
            # This is especially relevant since the osc-header now displays the
            # user-given session name.
            self.request.response.redirect("{0}/{1}?initial_view=1".format(
                survey.absolute_url(), "identification"))
示例#16
0
    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()
示例#17
0
    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()
示例#18
0
 def update(self):
     if redirectOnSurveyUpdate(self.request):
         return
     self.getStatus()
示例#19
0
 def update(self):
     if redirectOnSurveyUpdate(self.request):
         return
     self.getStatus()
示例#20
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        self.risk = self.request.survey.restrictedTraverse(
            self.context.zodb_path.split("/"))

        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            answer = reply.get("answer")
            self.context.comment = reply.get("comment")
            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) > DESCRIPTION_CROP_LENGTH:
                self.description_intro = ploneview.cropText(
                    stripped_description, 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.")
            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

            super(IdentificationView, self).update()
示例#21
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return
        context = aq_inner(self.context)

        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) > DESCRIPTION_CROP_LENGTH:
                self.description_intro = ploneview.cropText(
                    stripped_description, 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()
示例#22
0
 def update(self):
     self.session = SessionManager.session
     if redirectOnSurveyUpdate(self.request):
         return
     self.nodes = self.getNodes()
示例#23
0
    def update(self):
        if redirectOnSurveyUpdate(self.request):
            return

        context = aq_inner(self.context)
        self.errors = {}
        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            session = Session()
            errors = False
            reply["action_plans"] = []
            new_plans = []

            for i in range(0, len(reply['measure'])):
                # repoze.formapi treats an empty input for an int as a
                # validation error.
                measure = dict([p for p in reply['measure'][i].items()
                                if p[1].strip()])
                form = ActionPlanItemForm(params=measure)
                reply['action_plans'].append(measure)
                if not form.validate():
                    errors = True
                    reply['action_plans'][-1]['errors'] = \
                        dict(form.errors._dict)
                    if u'Start date is not before end date' in \
                            form.errors._messages:
                        reply['action_plans'][-1]['errors'][
                            'planning_start_date'] = [
                                u'Start date is not before end date']
                    continue

                if len(measure) > 2:
                    new_plans.append(model.ActionPlan(
                        action_plan=form.data["action_plan"],
                        prevention_plan=form.data["prevention_plan"],
                        requirements=form.data["requirements"],
                        responsible=form.data["responsible"],
                        budget=form.data["budget"],
                        planning_start=self._fieldsToDate(
                            form.data["planning_start_year"],
                            form.data["planning_start_month"],
                            form.data["planning_start_day"]),
                        planning_end=self._fieldsToDate(
                            form.data["planning_end_year"],
                            form.data["planning_end_month"],
                            form.data["planning_end_day"]),
                    ))
            if errors:
                self.data = reply
            else:
                context.comment = reply.get("comment")
                context.priority = reply.get("priority")

                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()
                        self.request.response.redirect(url)
                        return
                else:
                    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.request.response.redirect(url)
                        return

                url = QuestionURL(
                    self.request.survey, next, phase="actionplan")
                self.request.response.redirect(url)
                return
        else:
            if len(context.action_plans) == 0:
                context.action_plans.append(model.ActionPlan())
            self.data = context

        self.risk = risk = self.request.survey.restrictedTraverse(
            context.zodb_path.split("/"))
        self.title = context.parent.title
        self.tree = getTreeData(
            self.request, context,
            filter=self.question_filter, phase="actionplan")
        self.solutions = [solution for solution in risk.values()
                          if ISolution.providedBy(solution)]
        super(ActionPlanView, self).update()
示例#24
0
文件: risk.py 项目: EU-OSHA/Euphorie
    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()
示例#25
0
文件: risk.py 项目: EU-OSHA/Euphorie
    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()
示例#26
0
文件: risk.py 项目: euphorie/Euphorie
    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")
            self.description = self.risk.description
            # Italian special
            if IItalyIdentificationPhaseSkinLayer.providedBy(self.request):
                self.skip_evaluation = True
                self.description += u"""<p>Tutte le misure sono riepilogate
                nella tabella accessibile dal riquadro sottostante tramite il
                link “risorse aggiuntive” e vanno selezionate nella sezione
                misure/programma (almeno quelle obbligatorie).</p>
                """
            else:
                self.skip_evaluation = False
            stripped_description = StripMarkup(self.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

            super(IdentificationView, self).update()