示例#1
0
    def addStatistic(self, REQUEST, question=None, meta_type=None):
        """Add a statistic for question.

            @param question: id of the question
            @param meta_type: metatype of the statistic
        """
        err = []
        if not question:
            err.append('Please select a question')
        if not meta_type:
            err.append('Please select a statistic type')
        if err:
            self.setSessionErrorsTrans(err)
            return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)

        statistic_cls = STATISTICS[meta_type]
        question = self.getWidget(question)
        try:
            return manage_addStatistic(statistic_cls,
                                       self,
                                       genObjectId(question.title),
                                       question=question,
                                       REQUEST=REQUEST)
        except TypeError:
            if not REQUEST:
                raise
            err = sys.exc_info()
            LOG('NaayaSurvey.statistics.manage_addStatistic', DEBUG,
                'Error creating statistic %s for question %s' % (statistic_cls, question.absolute_url()), error=err)
            self.setSessionErrorsTrans('"${meta_label}" can\'t be used for question "${title}"',
                meta_label=statistic_cls.meta_label, title=question.title)
            return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
    def addStatistic(self, REQUEST, question=None, meta_type=None):
        """Add a statistic for question.

            @param question: id of the question
            @param meta_type: metatype of the statistic
        """
        err = []
        if not question:
            err.append('Please select a question')
        if not meta_type:
            err.append('Please select a statistic type')
        if err:
            self.setSessionErrorsTrans(err)
            return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)

        statistic_cls = STATISTICS[meta_type]
        question = self.getWidget(question)
        try:
            return manage_addStatistic(statistic_cls,
                                       self,
                                       genObjectId(question.title),
                                       question=question,
                                       REQUEST=REQUEST)
        except TypeError:
            if not REQUEST:
                raise
            err = sys.exc_info()
            LOG('NaayaSurvey.statistics.manage_addStatistic', DEBUG,
                'Error creating statistic %s for question %s' % (statistic_cls, question.absolute_url()), error=err)
            self.setSessionErrorsTrans('"${meta_label}" can\'t be used for question "${title}"',
                meta_label=statistic_cls.meta_label, title=question.title)
            return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
示例#3
0
    def generateFullReport(self, title='', REQUEST=None):
        """Generate a full report"""
        if not title:
            if REQUEST is None:
                raise ValueError('Field title is required')
            self.setSessionErrorsTrans('Field title is required')
            return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)

        report_id = manage_addSurveyReport(self, title=title)
        report = self._getOb(report_id)
        sortorder = 1
        for question in self.getSortedWidgets():
            stat_classes = []
            if isinstance(question, LabelWidget):
                pass
            elif isinstance(question, MultipleChoiceWidget):
                stat_classes.extend([
                    MultipleChoiceTabularStatistic,
                    MultipleChoiceCssBarChartStatistic,
                    MultipleChoiceGoogleBarChartStatistic,
                    MultipleChoicePieChartStatistic
                ])

            elif isinstance(question, ComboboxMatrixWidget):
                stat_classes.extend([ComboboxMatrixTabularStatistic])
            elif isinstance(question, MatrixWidget):
                stat_classes.extend(
                    [MatrixTabularStatistic, MatrixCssBarChartStatistic])

            elif isinstance(question, StringWidget) or isinstance(
                    question, TextAreaWidget):
                stat_classes.extend([TextAnswerListing])

            else:
                stat_classes.extend([SimpleTabularStatistic])

            for stat_class in stat_classes:
                manage_addStatistic(stat_class,
                                    report,
                                    question=question,
                                    sortorder=sortorder)
                sortorder += 1
        if REQUEST is not None:
            REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
        return report_id
    def generateFullReport(self, title='', REQUEST=None):
        """Generate a full report"""
        if not title:
            if REQUEST is None:
                raise ValueError('Field title is required')
            self.setSessionErrorsTrans('Field title is required')
            return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)

        report_id = manage_addSurveyReport(self, title=title)
        report = self._getOb(report_id)
        sortorder = 1
        for question in self.getSortedWidgets():
            stat_classes = []
            if isinstance(question, LabelWidget):
                pass
            elif isinstance(question, MultipleChoiceWidget):
                stat_classes.extend([MultipleChoiceTabularStatistic,
                                     MultipleChoiceCssBarChartStatistic,
                                     MultipleChoiceGoogleBarChartStatistic,
                                     MultipleChoicePieChartStatistic])

            elif isinstance(question, ComboboxMatrixWidget):
                stat_classes.extend([ComboboxMatrixTabularStatistic])
            elif isinstance(question, MatrixWidget):
                stat_classes.extend([MatrixTabularStatistic,
                                     MatrixCssBarChartStatistic])

            elif isinstance(question, StringWidget) or isinstance(question, TextAreaWidget):
                stat_classes.extend([TextAnswerListing])

            else:
                stat_classes.extend([SimpleTabularStatistic])

            for stat_class in stat_classes:
                manage_addStatistic(stat_class,
                                    report,
                                    question=question,
                                    sortorder=sortorder)
                sortorder += 1
        if REQUEST is not None:
            REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
        return report_id