Ejemplo n.º 1
0
def add_question(src, qtext, q_idx, atext_list):
    if not q_idx in q_dict:
        try:
            q = Question.objects.get(source=src, order=q_idx)
            assert q.text == qtext
        except Question.DoesNotExist:
            q = Question(source=src, order=q_idx)
        q.text = qtext
        q.save()
        q.opt_dict = {}
        q_dict[q_idx] = q
    else:
        q = q_dict[q_idx]
        assert q.text == qtext

    for idx, atext in enumerate(atext_list):
        if not idx in q.opt_dict:
            try:
                opt = Option.objects.get(question=q, order=idx)
                assert opt.name == atext
            except Option.DoesNotExist:
                opt = Option(question=q, order=idx)
            opt.name = atext
            opt.save()
            q.opt_dict[idx] = opt
        else:
            assert q.opt_dict[idx].name == atext
    return q
Ejemplo n.º 2
0
def add_question(src, qtext, q_idx, atext_list):
    if not q_idx in q_dict:
        try:
            q = Question.objects.get(source=src, order=q_idx)
            assert q.text == qtext
        except Question.DoesNotExist:
            q = Question(source=src, order=q_idx)
        q.text = qtext
        q.save()
        q.opt_dict = {}
        q_dict[q_idx] = q
    else:
        q = q_dict[q_idx]
        assert q.text == qtext

    for idx, atext in enumerate(atext_list):
        if not idx in q.opt_dict:
            try:
                opt = Option.objects.get(question=q, order=idx)
                assert opt.name == atext
            except Option.DoesNotExist:
                opt = Option(question=q, order=idx)
            opt.name = atext
            opt.save()
            q.opt_dict[idx] = opt
        else:
            assert q.opt_dict[idx].name == atext
    return q