Exemple #1
0
 def _get_foo_question(self, correct=2):
     """ Return a Question """
     class Question: pass
     class Answer: pass
     q = Question()
     q.text = 'How many'
     q.answers = []
     for i in range(4):
         a = Answer()
         a.id, a.text, a.correct = i, str(i), True if i == correct else False
         q.answers.append(a)
     return q
Exemple #2
0
 def _get_foo_question(self, correct=2):
     """ Return a Question """
     class Question: pass
     class Answer: pass
     q = Question()
     q.text = 'How many'
     q.answers = []
     for i in range(4):
         a = Answer()
         a.id, a.text, a.correct = i, str(i), True if i == correct else False
         q.answers.append(a)
     return q
Exemple #3
0
def add_question(question):
    """ question is a dictionary with the following keys:
        'text': the question text (string)
        'answer_type': whether the question is single choice or multiple choice (string)
        'answers': a dictionary of answers with the following keys:
            'text': the answer text (string)
            'correct': whether the answer is correct (boolean)
        'proposed_by': the user that proposed the question (User object)
        'endorsed_by': the user endorsing the question (User object)
        'active': whether the question is active (boolean)
        'category': the question category (i.e. quiz) (Category object)
        'tag': the question primary tag (from file name) (Tag object)
        'file_tags': secondary tags (from file contents) (array of Tag objects)
    """
    q = Question()
    q.save()
    q.text = question['text']
    q.answer_type = question['answer_type']
    q.save()

    if question['proposed_by']:
        q.proposed_by = question['proposed_by']
    q.save()

    if question['endorsed_by']:
        q.endorsed_by = question['endorsed_by']
    q.save()

    q.active = question['active']

    if question['category']:
        q.category = question['category']
    q.save()

    if question['tag']:
        q.tags.add(question['tag'])
        q.save()

    if question['file_tags']:
        for tag in question['file_tags']:
            q.tags.add(tag)
        q.save()

    for answer in question['answers']:
        a = Answer(question=q, **answer)
        a.save()

    return q
Exemple #4
0
def add_question(question):
    """ question is a dictionary with the following keys:
        'text': the question text (string)
        'answer_type': whether the question is single choice or multiple choice (string)
        'answers': a dictionary of answers with the following keys:
            'text': the answer text (string)
            'correct': whether the answer is correct (boolean)
        'proposed_by': the user that proposed the question (User object)
        'endorsed_by': the user endorsing the question (User object)
        'active': whether the question is active (boolean)
        'category': the question category (i.e. quiz) (Category object)
        'tag': the question primary tag (from file name) (Tag object)
        'file_tags': secondary tags (from file contents) (array of Tag objects)
    """
    q = Question()
    q.save()
    q.text = question['text']
    q.answer_type = question['answer_type']
    q.save()

    if question['proposed_by']:
        q.proposed_by = question['proposed_by']
    q.save()

    if question['endorsed_by']:
        q.endorsed_by = question['endorsed_by']
    q.save()

    q.active = question['active']

    if question['category']:
        q.category = question['category']
    q.save()

    if question['tag']:
        q.tags.add(question['tag'])
        q.save()

    if question['file_tags']:
        for tag in question['file_tags']:
            q.tags.add(tag)
        q.save()

    for answer in question['answers']:
        a = Answer(question=q, **answer)
        a.save()

    return q