示例#1
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        for i in range(self.number_of_questions.data):
            question = md.Question(
                text=self.question_text.data or _('Question %(num)s', num=i+1),
                order_number=i+1,
                show_values=True,
                container=section
            )
            md.db.session.add(question)
            for j in range(self.number_of_choices.data):
                md.db.session.add(md.Value(
                    text=_('Answer'),
                    question=question,
                    order_number=j+1,
                    points=0
                ))

        return section
示例#2
0
    def _add_section_(self):
        section = model.Section()
        result = self.view.section_dialog(section)
        if result == gtk.RESPONSE_OK:
            document = self._get_document_()
            document.append(section)
            # tags:
            xml_start = "<title>"
            xml_end = "</title>"

            # Add tag:
            cursor_mark = document.buffer.get_insert()
            cursor = document.buffer.get_iter_at_mark(cursor_mark)
            mark = document.buffer.create_mark(section.id, cursor, True)

            xml_tag = '<section id="%s">' % section.id
            document.buffer.insert_with_tags_by_name(cursor, xml_tag,
                                                     "invisible")
            # Title start tag
            document.buffer.insert_with_tags_by_name(cursor, xml_start,
                                                     "invisible")

            # Add title:
            document.buffer.insert_with_tags_by_name(cursor, section.title,
                                                     "bold", "uneditable")
            # Title end tag
            document.buffer.insert_with_tags_by_name(cursor, xml_end,
                                                     "invisible")

            # line break
            document.buffer.insert(cursor, "\n")

            # Ask the model to notify the observers:
            self.model.notify()
示例#3
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        for i in range(self.number_of_questions.data):
            question = md.Question(
                text=_('Statement %(num)s', num=i+1),
                order_number=i+1,
                show_values=False,
                bonus=True,
                container=section
            )
            md.db.session.add(question)
            for ans in self.answer.data.split(','):
                text = ans.strip()
                md.db.session.add(md.Value(
                    text=text,
                    question=question,
                    allowed_misses=int(len(text) / 4) + 1,
                    points=self.number_of_questions.data-i
                ))

        return section
示例#4
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        answers = [x.strip() for x in self.answers.data.split(',')]

        for i in range(len(answers)):
            question = md.Question(
                text=self.question_text.data or _('Question %(num)s', num=i+1),
                order_number=i+1,
                show_values=True,
                container=section
            )
            md.db.session.add(question)
            for (j, ans) in enumerate(answers):
                md.db.session.add(md.Value(
                    text=ans,
                    question=question,
                    order_number=j+1,
                    points=0
                ))

        return section
示例#5
0
def simple_category():
    category = model.Category('category', 'category desc', 'category')
    category.meta = {
        'id': 'category id',
        'webtranslateit_ids': {
            'content': 'category translate id'
        }
    }
    section = model.Section(category, 'section', 'section desc', 'section')
    section.meta = {
        'id': 'section id',
        'webtranslateit_ids': {
            'content': 'section translate id'
        }
    }
    article = model.Article(section, 'article', 'body', 'article')
    article.meta = {
        'id': 'article id',
        'webtranslateit_ids': {
            'body': 'body translate id',
            'content': 'article translate id'
        }
    }
    category.sections.append(section)
    section.articles.append(article)
    return category
示例#6
0
 def fetch(self):
     categories = []
     zendesk_categories = self.req.get_items(model.Category)
     for zendesk_category in zendesk_categories:
         category_filename = utils.slugify(zendesk_category['name'])
         category = model.Category(zendesk_category['name'],
                                   zendesk_category['description'],
                                   category_filename)
         print('Category %s created' % category.name)
         category.meta = zendesk_category
         zendesk_sections = self.req.get_items(model.Section, category)
         categories.append(category)
         for zendesk_section in zendesk_sections:
             section_filename = utils.slugify(zendesk_section['name'])
             section = model.Section(category, zendesk_section['name'],
                                     zendesk_section['description'],
                                     section_filename)
             print('Section %s created' % section.name)
             section.meta = zendesk_section
             zendesk_articles = self.req.get_items(model.Article, section)
             category.sections.append(section)
             for zendesk_article in zendesk_articles:
                 body = html2text.html2text(zendesk_article.get('body', ''))
                 article_filename = utils.slugify(zendesk_article['title'])
                 article = model.Article(section, zendesk_article['title'],
                                         body, article_filename)
                 print('Article %s created' % article.name)
                 article.meta = zendesk_article
                 section.articles.append(article)
     return categories
 def fetch(self):
     categories = []
     zendesk_categories = self.req.get_items(model.Category)
     for zendesk_category in zendesk_categories:
         category_filename = utils.slugify(zendesk_category['name'])
         category = model.Category(zendesk_category['name'],
                                   zendesk_category['description'],
                                   category_filename)
         print('Category %s created' % category.name)
         category.meta = zendesk_category
         zendesk_sections = self.req.get_items(model.Section, category)
         categories.append(category)
         for zendesk_section in zendesk_sections:
             section_filename = utils.slugify(zendesk_section['name'])
             section = model.Section(category, zendesk_section['name'],
                                     zendesk_section['description'],
                                     section_filename)
             print('Section %s created' % section.name)
             section.meta = zendesk_section
             zendesk_articles = self.req.get_items(model.Article, section)
             category.sections.append(section)
             for zendesk_article in zendesk_articles:
                 logging.debug('Article Info:' + zendesk_article['title'])
                 if zendesk_article['body']:
                     body = h2t.handle(zendesk_article.get('body', ''))
                     article_filename = utils.slugify(
                         zendesk_article['title'])
                     article = model.Article(section,
                                             zendesk_article['title'], body,
                                             article_filename)
                     print('Article %s created' %
                           article.name.encode('utf-8').strip())
                     article.meta = zendesk_article
                     section.articles.append(article)
     return categories
示例#8
0
文件: test_model.py 项目: sscst/argon
 def add_section(self, sectionname, description):
     u'''
     增加一个讨论区。
     '''
     print 'Add Section : [%s] %s' % (sectionname, description)
     s = model.Section(sectionname=sectionname, description=description)
     s.save()
     print 'All DONE.'
示例#9
0
    def create(self, quiz: md.Quiz):
        section = md.Section(
            user_id=current_user.id,
            container=quiz,
            order_number=self.order_number.data,
            name=self.name.data
        )
        md.db.session.add(section)

        order_number = 1

        for i in range(self.number_of_questions.data-1):
            question = md.Question(
                text=_('Question %(num)s', num=i+1),
                order_number=order_number,
                show_values=False,
                container=section
            )
            order_number += 1
            md.db.session.add(question)
            md.db.session.add(md.Value(
                text=_('Answer'),
                question=question,
                allowed_misses=3,
                points=1
            ))
            if i < self.opportunities.data:
                question = md.Question(
                    text=_('What is the connection? (+%(num)s/-1)', num=self.opportunities.data - i),
                    order_number=order_number,
                    show_values=False,
                    bonus=True,
                    container=section
                )
                order_number += 1
                md.db.session.add(question)
                for ans in self.connection.data.split(','):
                    text = ans.strip()
                    md.db.session.add(md.Value(
                        text=text,
                        question=question,
                        allowed_misses=int(len(text) / 4) + 1,
                        points=self.opportunities.data + 1 - i
                    ))

        question = md.Question(
            text=_('What is the connection?'),
            order_number=order_number,
            show_values=False,
            bonus=True,
            container=section
        )
        md.db.session.add(question)
        for ans in self.connection.data.split(','):
            text = ans.strip()
            md.db.session.add(md.Value(
                text=text,
                question=question,
                allowed_misses=int(len(text) / 4) + 1,
                points=1
            ))


        return section
示例#10
0
 def _instantiate_section(self, category, zendesk_section):
     attributes, filename = self._get_group_attributes_and_filename(
         zendesk_section)
     section = model.Section(category, attributes, filename)
     section.meta = zendesk_section
     return section