Example #1
0
def task(request, id):
    task = Task.objects.get(id=id)
    task_categories = task.categories.all()
    task_age_groups = task.age_group_categories()

    content_categories = all_cat()
    age_groups = all_ages()
    difficulty_levels = all_dif()

    return render_to_response("task/details.html", locals(), context_instance=RequestContext(request))
Example #2
0
def translate(request, id):
    all_languages = all_lang()
    task_translation = TaskTranslation.objects.get(id=id)

    task = task_translation.task

    answer_multiple_choice = task_translation.answer_set

    categories = task.categories.all()
    task_age_groups = AgeGroupTask.objects.filter(task_id=task.id)

    content_categories = all_cat()
    age_groups = all_ages()
    difficulty_levels = all_dif()

    if request.method == 'POST':
        title = request.POST['title']
        body = request.POST['body']
        language = request.POST['language']
        solution = request.POST['solution']
        comment = request.POST['diff']
        correctness = request.POST['correctness']
        it_is_informatics = request.POST['informatics']

        answers = get_answers(request.POST)
        age_groups = get_age_groups(request.POST)
        categories = get_categories(request.POST)

        new_trans = TaskTranslation(title=title, body=body, solution=solution,
                                           task_id=task.id, language_locale=language,
                                           it_is_informatics=it_is_informatics, comment=comment)


        new_trans.save()

        for i in range(0, 4):
            answers[i].trans_id = new_trans.id
            answers[i].save()
            if int(i) == int(correctness):
                new_trans.correct_answer_id = answers[i].id

        new_trans.save()



        return redirect('/show/' + str(task.id) + '?language=' + str(language))

    return render_to_response("task/translate.html", locals(), context_instance=RequestContext(request))
Example #3
0
def new_from(request, id):
    parent_id = None
    all_languages = all_lang()

    if request.method == 'POST':
        title = request.POST['title']
        body = request.POST['body']
        language = request.POST['language']
        solution = request.POST['solution']
        comment = request.POST['diff']
        correctness = request.POST['correctness']
        it_is_informatics = request.POST['informatics']

        answers = get_answers(request.POST, language)
        age_groups = get_age_groups(request.POST)
        categories = get_categories(request.POST)

        new_task = Task(parent_id=parent_id, author=request.user)
        new_task.save()

        for category_id in categories:
            c = Category.objects.get(id=categories[category_id])
            new_task.categories.add(c)

        new_task.save()

        answer_multiple_choice = Answer(task_id=new_task.id, correctness=(int(correctness) + 1))
        answer_multiple_choice.save()

        for i in range(0, 4):
            answers[i].answer_multiple_choice_id = answer_multiple_choice.id
            answers[i].save()

        for i in range(0, len(age_groups)):
            age_groups[i].task_id = new_task.id
            age_groups[i].save()

        national_problem = TaskTranslation(title=title, body=body, solution=solution,
                                           task_id=new_task.id, language_locale=language,
                                           it_is_informatics=it_is_informatics, comment=comment)
        national_problem.save()

        return redirect('/show/' + str(new_task.id))

    task = Task.objects.get(id=id)
    task_translation = TaskTranslation.objects.filter(task_id=id)
    task_translation = task_translation[0]

    answers = Answer.objects.filter(task_id=id)

    answers_id = map(lambda answer: answer.id, answers)
    answer_multiple_choice = AnswerTranslation.objects.filter(answer_multiple_choice_id__in=answers_id,
                                                              language_locale=task_translation.language_locale)

    task_categories = task.categories.all()
    task_age_groups = AgeGroupTask.objects.filter(task_id=task.id)

    content_categories = all_cat()
    age_groups = all_ages()
    difficulty_levels = all_dif()

    return render_to_response("task/edit.html", locals(), context_instance=RequestContext(request))