Ejemplo n.º 1
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()
Ejemplo n.º 2
0
def save_question_changes_from_post(project_id, post):
    """
    Saves all the Question objects in request.POST to the database (along with any answers)
    :param project_id: ID value of the project needed for attaching Questions to a project
    :param post: request.POST from the question management page form
    :return: void - Questions are saved directly to the database
    """
    current_project = Project.objects.get(pk=project_id)

    # Delete previous codes, answers and questions
    Code.objects.filter(message__in=current_project.message_set.all()).delete()
    Answer.objects.filter(question__in=Question.objects.filter(project=current_project)).delete()
    Question.objects.filter(project=current_project).delete()

    # Now save the new questions from scratch
    for key_i, value_i in post.items():
        if key_i.startswith("q_text_"):

            # get the number of the question in the form
            i = key_i[7:]
            q_text = value_i
            q_descr = ""

            # Now check if there is a description
            for key_j, value_j in post.items():
                if key_j.startswith("q_descr_" + i):
                    q_descr = value_j

            # Create the actual question object
            q = Question(project=current_project,
                         text=q_text,
                         description=q_descr)
            q.save()

            # Create a set of answers based on the current question
            save_answers_from_post(post, i, q)