Exemple #1
0
 def get_success_url(self):
     first_translation = TaskTranslation(
         task=self.object,
         language_locale=self.cleaned_data['language_locale'])
     first_translation.save()
     first_translation.create_default_answers()
     return reverse('tasktranslation_update',
                    kwargs={'pk': first_translation.pk})
Exemple #2
0
def tasks_translate(request, id):
    all_languages = settings.LANGUAGES
    task_translation = TaskTranslation.objects.get(id=id)
    task = task_translation.task
    answer_multiple_choice = task_translation.answer_set
    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)
        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(
            reverse('/show/' + str(task.id) + '?language=' + str(language)))
    return render(request,
                  "task/translate.html",
                  locals(),
                  context_instance=RequestContext(request))
Exemple #3
0
def tasks_save_translation(request):
    if request.method == 'GET':
        return redirect("/")
    if request.method == 'POST':
        if 'id' in request.POST:  # Updating object
            task_translation = TaskTranslation.objects.get(
                id=request.POST['id'])
            old_task_translation = TaskTranslation.objects.get(
                id=request.POST['id'])
            if not task_translation.title:
                old_task_translation.delete()
                task_translation.save()
            else:
                task_translation.save_new_version()
            # Delete if no title

        else:  # New task
            task = Task()
            task.save()
            task_translation = TaskTranslation(task=task)
            task_translation.language_locale = request.POST['language']
            task_translation.save()

        task_translation.title = request.POST['title']
        task_translation.body = request.POST['body']
        task_translation.solution = request.POST['solution']
        task_translation.comment = request.POST['diff']
        task_translation.it_is_informatics = request.POST['informatics']

        for i in range(0, 4):
            post_answer = request.POST.getlist("answer[" + str(i) + "]")
            answer = Answer(value=post_answer[0])
            answer.task_translation = task_translation
            answer.save()
            if int(i) == int(request.POST['correctness']):
                task_translation.correct_answer = answer

        task_translation.save()
    return redirect('tasks.display', task_translation.id)
Exemple #4
0
def tasks_new_from(request, id):
    task = get_object_or_404(Task, pk=id)
    translation0 = TaskTranslation(task_id=id)
    translation0.save()
    return task_translate(request, translation0.id)