def post(self, request, contest_slug, task_name):
     user = User.objects.get(username=request.user)
     try:
         task = get_task_by_contest_and_name(contest_slug, task_name,
                                             user.is_editor())
     except Exception as e:
         return HttpResponseBadRequest(e)
     translation = get_trans_by_user_and_task(user, task)
     content = request.POST['content']
     saved = request.POST['saved'] == 'true'
     edit_token = request.POST.get('edit_token', '')
     if translation.is_editable_by(user) or not can_user_change_translation(
             user, translation, edit_token) or not (task.is_published()
                                                    or user.is_editor()):
         return JsonResponse({
             'can_edit': False,
             'edit_token': '',
             'error': 'forbidden'
         })
     can_edit, new_edit_token = get_translate_edit_permission(
         translation, edit_token)
     translation.add_version(content, saved=saved)
     return JsonResponse({
         'can_edit': can_edit,
         'edit_token': new_edit_token
     })
 def post(self, request, id):
     edit_token = request.POST.get('edit_token', '')
     task = Task.objects.get(id=id)
     user = User.objects.get(username=request.user)
     if not (task.contest.public or user.is_editor):
         return HttpResponseBadRequest("There is no published task")
     translation = Translation.objects.get(user=user, task=task)
     if translation.is_editable_by(user) or user != translation.user:
         return HttpResponseForbidden()
     can_edit, new_edit_token = get_translate_edit_permission(
         translation, edit_token)
     return JsonResponse({
         'can_edit': can_edit,
         'edit_token': new_edit_token,
         'content': translation.get_latest_text()
     })