def validate(self, question_group_dict, key):
        """Validate the question group data sent from the form."""
        errors = []

        assert question_group_dict['version'] == self.SCHEMA_VERSION

        if not question_group_dict['description'].strip():
            errors.append('The question group must have a description.')

        descriptions = {
            question_group.description
            for question_group in QuestionGroupDAO.get_all()
            if not key or question_group.id != long(key)
        }
        if question_group_dict['description'] in descriptions:
            errors.append('The description must be different '
                          'from existing question groups.')

        if not question_group_dict['items']:
            errors.append(
                'The question group must contain at least one question.')

        items = question_group_dict['items']
        for index in range(0, len(items)):
            item = items[index]
            try:
                float(item['weight'])
            except ValueError:
                errors.append('Item %s must have a numeric weight.' %
                              (index + 1))

        return errors
Esempio n. 2
0
    def list_question_groups(self):
        """Prepare a list of question groups."""
        if not filer.is_editable_fs(self.app_context):
            return safe_dom.NodeList()

        all_questions = QuestionDAO.get_all()
        output = safe_dom.NodeList()
        if all_questions:
            output.append(
                safe_dom.Element('a',
                                 className='gcb-button gcb-pull-right',
                                 href='dashboard?action=add_question_group').
                add_text('Add Question Group')).append(
                    safe_dom.Element('div',
                                     style='clear: both; padding-top: 2px;'))
        output.append(safe_dom.Element('h3').add_text('Question Groups'))

        # TODO(jorr): Hook this into the datastore
        all_question_groups = QuestionGroupDAO.get_all()
        if all_question_groups:
            ol = safe_dom.Element('ol')
            for question_group in all_question_groups:
                edit_url = 'dashboard?action=edit_question_group&key=%s' % (
                    question_group.id)
                li = safe_dom.Element('li')
                li.add_text(question_group.description).add_child(
                    safe_dom.Entity(' ')).add_child(
                        safe_dom.Element('a',
                                         href=edit_url).add_text('[Edit]'))
                ol.add_child(li)
            output.append(ol)
        else:
            output.append(safe_dom.Element('blockquote').add_text('< none >'))

        return output
    def validate(self, question_group_dict, key):
        """Validate the question group data sent from the form."""
        errors = []

        assert question_group_dict['version'] == self.SCHEMA_VERSION

        if not question_group_dict['description'].strip():
            errors.append('The question group must have a description.')

        descriptions = {question_group.description for question_group
                        in QuestionGroupDAO.get_all()
                        if not key or question_group.id != long(key)}
        if question_group_dict['description'] in descriptions:
            errors.append('The description must be different '
                          'from existing question groups.')

        if not question_group_dict['items']:
            errors.append(
                'The question group must contain at least one question.')

        items = question_group_dict['items']
        for index in range(0, len(items)):
            item = items[index]
            try:
                float(item['weight'])
            except ValueError:
                errors.append(
                    'Item %s must have a numeric weight.' % (index + 1))

        return errors
Esempio n. 4
0
    def list_question_groups(self):
        """Prepare a list of question groups."""
        if not filer.is_editable_fs(self.app_context):
            return safe_dom.NodeList()

        all_questions = QuestionDAO.get_all()
        output = safe_dom.NodeList()
        if all_questions:
            output.append(
                safe_dom.Element(
                    'a', className='gcb-button gcb-pull-right',
                    href='dashboard?action=add_question_group'
                ).add_text('Add Question Group')
            ).append(
                safe_dom.Element(
                    'div', style='clear: both; padding-top: 2px;'
                )
            )
        output.append(
            safe_dom.Element('h3').add_text('Question Groups')
        )

        # TODO(jorr): Hook this into the datastore
        all_question_groups = QuestionGroupDAO.get_all()
        if all_question_groups:
            ol = safe_dom.Element('ol')
            for question_group in all_question_groups:
                edit_url = 'dashboard?action=edit_question_group&key=%s' % (
                    question_group.id)
                li = safe_dom.Element('li')
                li.add_text(
                    question_group.description
                ).add_child(
                    safe_dom.Entity('&nbsp;')
                ).add_child(
                    safe_dom.Element('a', href=edit_url).add_text('[Edit]'))
                ol.add_child(li)
            output.append(ol)
        else:
            output.append(safe_dom.Element('blockquote').add_text('< none >'))

        return output
Esempio n. 5
0
 def validate_group_description(self, group_description, errors):
     descriptions = [gr.description for gr in QuestionGroupDAO.get_all()]
     if group_description in descriptions:
         errors.append('Non-unique group description.')