Beispiel #1
0
def save_answers_from_post(post, i, q):
    """
    Find each answer for the current question and save it in the database
    :param post: request.POST from the question management page form
    :param i: the i-th question in the form
    :param q: the Question object itself
    :return: void - Answers are saved directly to the database
    """
    for key, value in post.items():
        if key.startswith("a_" + i):
            a_id = q.project.title + "_" + q.text + "_" + value
            a_id = ''.join(a_id.split()).lower()
            a = Answer(question=q,
                       value=a_id,
                       text=value)
            a.save()
Beispiel #2
0
    def _create_data(self):

        u1 = User.objects.create_user('valerio', '*****@*****.**', 'valerio')
        u1.save()

        u2 = User.objects.create_user('bob', '*****@*****.**', 'bob')
        u2.save()

        self.create_users()
        self.create_projects()

        p1 = Project.objects.filter(title='Twitter demo 2015')

        self.load_tweets_into(*p1)
        self.create_progress_for(*p1)

        v1 = Question(project=p1[0],
                      text='Is the message subjective or objective?',
                      description='Describes whether the message is a personal '
                      'opinion or neutral information.')
        v1.save()

        v2 = Question(project=p1[0],
                      text='In what language is the message written?',
                      description='Describes whether the message is in English, '
                      'Dutch or some other language.')
        v2.save()

        c1_1 = Answer(question=v1,
                      text='The message is subjective.')
        c1_1.save()

        c1_2 = Answer(question=v1,
                      text='The message is objective.')
        c1_2.save()

        c2_1 = Answer(question=v2,
                      text='The message is in English.')
        c2_1.save()

        c2_2 = Answer(question=v2,
                      text='The message is in Dutch.')
        c2_2.save()

        c2_3 = Answer(question=v2,
                      text='The message is in another language.')
        c2_3.save()

        # Update value variables of answers
        c1_1.value = create_value_from_answer(c1_1)
        c1_2.value = create_value_from_answer(c1_2)
        c2_1.value = create_value_from_answer(c2_1)
        c2_2.value = create_value_from_answer(c2_2)
        c2_3.value = create_value_from_answer(c2_3)
        c1_1.save()
        c1_2.save()
        c2_1.save()
        c2_2.save()
        c2_3.save()