Esempio n. 1
0
    def __call__(self):
        if not self.webhelpers.can_view_session:
            # The user cannot call this view, to go the sessions overview.
            return self.request.response.redirect(self.webhelpers.client_url)

        utils.setLanguage(self.request, self.survey, self.survey.language)
        return super(Involve, self).__call__()
Esempio n. 2
0
    def publishTraverse(self, request, name):
        request.survey = self.context
        utils.setLanguage(request, self.context, self.context.language)

        if name not in ["view", "index_html"] and \
                not self.hasValidSession(request):
            request.response.redirect(
                    aq_parent(aq_parent(self.context)).absolute_url(),
                    lock=True)
            return self.context

        if name not in self.phases:
            return super(SurveyPublishTraverser, self)\
                    .publishTraverse(request, name)

        # Decorate the request with the right skin layer and add to the aq path
        directlyProvides(request, self.phases[name],
                         *directlyProvidedBy(request))
        self.context = PathGhost(name).__of__(self.context)

        session = SessionManager.session
        tree_id = find_sql_context(session.id,
                request['TraversalRequestNameStack'])
        if tree_id is not None:
            return build_tree_aq_chain(self.context, tree_id)

        # No SQL based traversal possible, return the existing context with the
        # new skin layer applied
        return self.context
Esempio n. 3
0
 def __call__(self):
     if self.webhelpers.redirectOnSurveyUpdate():
         return
     utils.setLanguage(self.request, self.survey, self.survey.language)
     self.update()
     self.getStatus()
     return super(Status, self).__call__()
Esempio n. 4
0
 def update(self):
     utils.setLanguage(self.request, self.context)
     if self.request.environ["REQUEST_METHOD"] == "POST":
         reply = self.request.form
         if reply["action"] == "new":
             self._NewSurvey(reply)
         elif reply["action"] == "continue":
             self._ContinueSurvey(reply)
     self._updateSurveys()
Esempio n. 5
0
 def update(self):
     utils.setLanguage(self.request, self.survey, self.survey.language)
     if not self.profile_questions or self.request.method == "POST":
         new_session = self.setupSession()
         self.request.response.redirect(
             "{base_url}/++session++{session_id}/{target}".format(
                 base_url=self.context.aq_parent.absolute_url(),
                 session_id=new_session.id,
                 target=self.next_view_name,
             ))
Esempio n. 6
0
    def __call__(self):
        if self.webhelpers.redirectOnSurveyUpdate():
            return

        survey = self.webhelpers._survey
        utils.setLanguage(self.request, survey, survey.language)

        if self.request.environ["REQUEST_METHOD"] == "POST":
            reply = self.request.form
            if "risk_id" in reply:
                self.handle_measure_configuration(reply)

        self.request.RESPONSE.addHeader("Cache-Control", "public,max-age=60")
        return self.index()
Esempio n. 7
0
 def __call__(self):
     """Render the page only if the user has edit rights,
     otherwise redirect to the start page of the session.
     """
     if not self.webhelpers.can_edit_session:
         return self.request.response.redirect(self.context.absolute_url() +
                                               "/@@start")
     if self.webhelpers.redirectOnSurveyUpdate():
         return
     if self.webhelpers.integrated_action_plan:
         return self.request.response.redirect(self.context.absolute_url() +
                                               "/@@report")
     utils.setLanguage(self.request, self.survey, self.survey.language)
     return super(ActionPlanView, self).__call__()
Esempio n. 8
0
 def update(self):
     utils.setLanguage(self.request, self.context)
     if self.request.environ["REQUEST_METHOD"] == "POST":
         reply = self.request.form
         if reply["action"] == "new":
             self._NewSurvey(reply)
         elif reply["action"] == "continue":
             self._ContinueSurvey(reply)
     else:
         survey = aq_inner(self.context)
         dbsession = SessionManager.session
         if dbsession is not None and \
                 dbsession.zodb_path == utils.RelativePath(
                                     self.request.client, survey):
             self.request.response.redirect("%s/resume?initial_view=1" %
                                            survey.absolute_url())
Esempio n. 9
0
 def __call__(self):
     if not self.webhelpers.can_edit_session:
         return self.request.response.redirect(self.context.absolute_url() +
                                               "/@@start")
     if not self.next_url:
         msg = _(
             "There is not enough information to proceed to the identification phase"
         )
         api.portal.show_message(msg, self.request, "error")
         return self.request.response.redirect(self.context.absolute_url() +
                                               "/@@start")
     utils.setLanguage(self.request, self.survey, self.survey.language)
     if self.webhelpers.use_involve_phase:
         self.request.RESPONSE.redirect(self.next_url)
     else:
         return super(Identification, self).__call__()
Esempio n. 10
0
 def update(self):
     utils.setLanguage(self.request, self.context)
     if self.request.environ["REQUEST_METHOD"] == "POST":
         reply = self.request.form
         if reply["action"] == "new":
             self._NewSurvey(reply)
         elif reply["action"] == "continue":
             self._ContinueSurvey(reply)
     else:
         survey = aq_inner(self.context)
         dbsession = SessionManager.session
         if dbsession is not None and \
                 dbsession.zodb_path == utils.RelativePath(
                                     self.request.client, survey):
             self.request.response.redirect(
                     "%s/resume" % survey.absolute_url())
Esempio n. 11
0
    def update(self):
        self.verify_view_permission()
        utils.setLanguage(self.request, self.survey, self.survey.language)
        super(Start, self).update()
        if self.request.method != "POST":
            return

        data, errors = self.extractData()
        if errors:
            return
        self._set_data(data)

        # Optimize: if the form was auto-submitted, we know that we want to
        # show the "start" page again
        if "form.button.submit" in self.request:
            return self.request.response.redirect(
                addTokenToUrl("%s/@@profile" % self.context.absolute_url()))
Esempio n. 12
0
    def __call__(self):
        # Render the page only if the user has edit rights,
        # otherwise redirect to the start page of the session.
        if not self.webhelpers.can_edit_session:
            return self.request.response.redirect(
                self.context.aq_parent.absolute_url() + "/@@start"
            )

        if self.webhelpers.redirectOnSurveyUpdate():
            return

        context = aq_inner(self.context)
        utils.setLanguage(self.request, self.survey, self.survey.language)

        module = self.webhelpers.traversed_session.restrictedTraverse(
            context.zodb_path.split("/")
        )
        if self.request.environ["REQUEST_METHOD"] == "POST":
            return self.save_and_continue(module)

        if IProfileQuestion.providedBy(module) and context.depth == 2:

            if self.next_question is None:
                url = self.next_phase_url
            else:
                url = self.next_question_url
            return self.request.response.redirect(url)

        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 self.next_question
        if ICustomRisksModule.providedBy(module):
            template = ViewPageTemplateFile(
                "templates/module_identification_custom.pt"
            ).__get__(self, "")
        else:
            template = self.template
        return template()
Esempio n. 13
0
    def publishTraverse(self, request, name):
        request.survey = self.context
        utils.setLanguage(request, self.context, self.context.language)

        if name not in ["view", "index_html"] and \
                not self.hasValidSession(request):
            request.response.redirect(
                    aq_parent(aq_parent(self.context)).absolute_url(),
                    lock=True)
            return self.context

        if name not in self.phases:
            return super(SurveyPublishTraverser, self)\
                    .publishTraverse(request, name)

        # Decorate the request with the right skin layer and add to the aq path

        # Some countries need to be marked specially. Check if this needs to be
        # done, and decorate the reques accordingly if yes.
        special = False
        for obj in aq_chain(aq_inner(self.context)):
            if IClientCountry.providedBy(obj):
                if obj.id in self.countries:
                    special = True
                    directlyProvides(
                        request, self.countries[obj.id][name],
                        *directlyProvidedBy(request))
                    break
        if not special:
            directlyProvides(request, self.phases[name],
                             *directlyProvidedBy(request))
        self.context = PathGhost(name).__of__(self.context)

        session = SessionManager.session
        tree_id = find_sql_context(session.id,
                request['TraversalRequestNameStack'])
        if tree_id is not None:
            return build_tree_aq_chain(self.context, tree_id)

        # No SQL based traversal possible, return the existing context with the
        # new skin layer applied
        return self.context
Esempio n. 14
0
    def publishTraverse(self, request, name):
        request.survey = self.context
        utils.setLanguage(request, self.context, self.context.language)

        if name not in ["view", "index_html"] and \
                not self.hasValidSession(request):
            request.response.redirect(aq_parent(aq_parent(
                self.context)).absolute_url(),
                                      lock=True)
            return self.context

        if name not in self.phases:
            return super(SurveyPublishTraverser, self)\
                    .publishTraverse(request, name)

        # Decorate the request with the right skin layer and add to the aq path

        # Some countries need to be marked specially. Check if this needs to be
        # done, and decorate the reques accordingly if yes.
        special = False
        for obj in aq_chain(aq_inner(self.context)):
            if IClientCountry.providedBy(obj):
                if obj.id in self.countries:
                    special = True
                    directlyProvides(request, self.countries[obj.id][name],
                                     *directlyProvidedBy(request))
                    break
        if not special:
            directlyProvides(request, self.phases[name],
                             *directlyProvidedBy(request))
        self.context = PathGhost(name).__of__(self.context)

        session = SessionManager.session
        tree_id = find_sql_context(session.id,
                                   request['TraversalRequestNameStack'])
        if tree_id is not None:
            return build_tree_aq_chain(self.context, tree_id)

        # No SQL based traversal possible, return the existing context with the
        # new skin layer applied
        return self.context
Esempio n. 15
0
    def __call__(self):
        self.verify_view_permission()
        if self.webhelpers.redirectOnSurveyUpdate():
            return

        session = self.context.session
        if self.request.method == "POST":
            session.report_comment = self.request.form.get("comment")

            url = "%s/@@report_company" % self.context.absolute_url()
            if (getattr(session, "company", None) is not None
                    and getattr(session.company, "country") is not None):
                url = "%s/@@report_view" % self.context.absolute_url()

            user = get_current_account()
            if getattr(user, "account_type", None) == config.GUEST_ACCOUNT:
                url = "%s/@@register_session?came_from=%s" % (
                    self.context.absolute_url(),
                    quote(url, ""),
                )
            return self.request.response.redirect(url)

        utils.setLanguage(self.request, self.survey, self.survey.language)
        return super(Report, self).__call__()
Esempio n. 16
0
 def update(self):
     if not getattr(aq_base(aq_inner(self.context)), 'regelhulp_id', None):
         log.error('OD entry, but survey has no regelhulp id.')
         raise NotFound()
     utils.setLanguage(self.request, self.context, self.context.language)
Esempio n. 17
0
    def __call__(self):
        # Render the page only if the user has edit rights,
        # otherwise redirect to the start page of the session.
        if not self.webhelpers.can_edit_session:
            return self.request.response.redirect(
                self.context.aq_parent.aq_parent.absolute_url() + "/@@start"
            )
        if self.webhelpers.redirectOnSurveyUpdate():
            return

        context = aq_inner(self.context)
        utils.setLanguage(self.request, self.survey, self.survey.language)
        if (IProfileQuestion.providedBy(self.module) and context.depth == 2) or (
            ICustomRisksModule.providedBy(self.module) and self.phase == "actionplan"
        ):
            next_question = FindNextQuestion(
                context, self.context.session, filter=self.question_filter
            )
            if next_question is None:
                if self.phase == ("identification", "evaluation"):
                    url = (
                        self.webhelpers.traversed_session.absolute_url()
                        + "/@@actionplan"
                    )
                elif self.phase == "actionplan":
                    url = self.webhelpers.traversed_session.absolute_url() + "/@@report"
            else:
                url = "{session_url}/{path}/@@actionplan".format(
                    session_url=self.webhelpers.traversed_session.absolute_url(),
                    path="/".join(next_question.short_path),
                )
            return self.request.response.redirect(url)

        self.title = self.context.title
        previous = FindPreviousQuestion(
            self.context, self.context.session, filter=self.question_filter
        )
        if previous is None:
            self.previous_url = "%s/@@%s" % (
                self.context.aq_parent.absolute_url(),
                self.phase,
            )
        else:
            self.previous_url = "{session_url}/{path}/@@{phase}".format(
                session_url=self.webhelpers.traversed_session.absolute_url(),
                path="/".join(previous.short_path),
                phase=self.phase,
            )
        next_question = FindNextQuestion(
            self.context, self.context.session, filter=self.question_filter
        )
        if next_question is None:
            self.next_url = (
                self.webhelpers.traversed_session.absolute_url() + "/@@report"
            )
        else:
            self.next_url = "{session_url}/{path}/@@{phase}".format(
                session_url=self.webhelpers.traversed_session.absolute_url(),
                path="/".join(next_question.short_path),
                phase=self.phase,
            )
        return self.index()
Esempio n. 18
0
 def update(self):
     super(SessionMixin, self).update()
     utils.setLanguage(self.request, self.survey, self.survey.language)
Esempio n. 19
0
 def __call__(self):
     utils.setLanguage(self.request, self.context,
                       getattr(self.context, "language", None))
     return super(Surveys, self).__call__()
Esempio n. 20
0
 def set_language(self):
     utils.setLanguage(self.request, self.context,
                       getattr(self.context, "language", None))
Esempio n. 21
0
 def set_language(self):
     utils.setLanguage(self.request, self.context, self.context.language)
Esempio n. 22
0
 def __call__(self):
     utils.setLanguage(self.request, self.context, self.language)
     return super(PublicCertificate, self).__call__()