예제 #1
0
    def handleUpload(self, action):
        (data, errors) = self.extractData()
        if errors:
            return

        input = self.parseInput(data["file"].data)
        if input is None:
            raise WidgetActionExecutionError("file",
                    Invalid(_("error_invalid_session_file",
                        default=u"Geen valide RI&E bestand.")))

        survey = self.findSurvey(input)
        if survey is None:
            raise WidgetActionExecutionError("file",
                    Invalid(_("error_unknown_survey",
                        default=u"De gebruikte vragenlijst bestaat niet op deze site.")))

        session = SessionManager.start(
                attr_unicode(input, "rienaam", u"RI&E import"), survey)
        self.updateCompany(input, session)
        (profile, keuzemap) = self.buildProfile(input, survey, session)
        BuildSurveyTree(survey, profile, session)
        self.updateAnswers(input, keuzemap, survey, session)

        question = FindFirstQuestion(dbsession=session)
        if question is None:
            transaction.get().doom()
            raise WidgetActionExecutionError("file",
                    Invalid(u"Deze RI&E is helaas teveel veranderd om te kunnen gebruiken."))
        self.request.response.redirect(
                QuestionURL(survey, question, phase="identification"))
예제 #2
0
    def buildProfile(self, input, survey, session):
        idmap = {}
        for profilequestion in survey.values():
            if not IProfileQuestion.providedBy(profilequestion):
                continue
            idmap[profilequestion.external_id] = profilequestion
        if not idmap:
            return ({}, {})

        profile = {}
        keuzemap = {}  # Map `keuze' to profile index
        for facet in input.profiel.facet:
            question = idmap.get(facet.attrib["vraag-id"])
            if question is None:
                continue
            if question.type == "optional":
                profile[question.id] = True
                keuzemap[facet.keuze.attrib["antwoord"]] = 0
            elif question.type == "repeat":
                profile[question.id] = []
                for (i, keuze) in enumerate(facet.keuze):
                    antwoord = attr_unicode(keuze, "antwoord")
                    profile[question.id].append(antwoord)
                    keuzemap[keuze.attrib["antwoord"]] = i

        return (profile, keuzemap)