@login_required
def edit_answer(request, question_id, answer_id):
 answer = get_object_or_404(Answer, pk=answer_id, question=question_id)
 answer_preview = None
 if (not answer.allows_edit(request.user)):
  raise PermissionDenied
 upload_imageattachment(request, answer)
 if (request.method == 'GET'):
  form = AnswerForm({'content': answer.content})
  return render(request, 'questions/edit_answer.html', {'form': form, 'answer': answer})
 form = AnswerForm(request.POST)
 if form.is_valid():
  answer.content = form.cleaned_data['content']
  answer.updated_by = request.user
  if ('preview' in request.POST):
   answer.updated = datetime.now()
   answer_preview = answer
  else:
   log.warning(('User %s is editing answer with id=%s' % (request.user, answer.id)))
   answer.save()
   return HttpResponseRedirect(answer.get_absolute_url())
 return render(request, 'questions/edit_answer.html', {'form': form, 'answer': answer, 'answer_preview': answer_preview})

@ login_required def edit_answer ( request , question_id , answer_id ) : answer = get_object_or_404 ( Answer , pk = answer_id , question = question_id ) answer_preview = None if ( not answer . allows_edit ( request . user ) ) : raise PermissionDenied upload_imageattachment ( request , answer ) if ( request . method == 'GET' ) : form = AnswerForm ( { 'content' : answer . content } ) return render ( request , 'questions/edit_answer.html' , { 'form' : form , 'answer' : answer } ) form = AnswerForm ( request . POST ) if form . is_valid ( ) : answer . content = form . cleaned_data [ 'content' ] answer . updated_by = request . user if ( 'preview' in request . POST ) : answer . updated = datetime . now ( ) answer_preview = answer else : log . warning ( ( 'User %s is editing answer with id=%s' % ( request . user , answer . id ) ) ) answer . save ( ) return HttpResponseRedirect ( answer . get_absolute_url ( ) ) return render ( request , 'questions/edit_answer.html' , { 'form' : form , 'answer' : answer , 'answer_preview' : answer_preview } )
edit an answer .