@xframe_options_sameorigin
@login_required
@process_document_path
def edit_attachment(request, document_slug, document_locale):
 document = get_object_or_404(Document, locale=document_locale, slug=document_slug)
 if (request.method != 'POST'):
  return redirect(document.get_edit_url())
 if (not allow_add_attachment_by(request.user)):
  raise PermissionDenied
 form = AttachmentRevisionForm(data=request.POST, files=request.FILES)
 if form.is_valid():
  revision = form.save(commit=False)
  revision.creator = request.user
  attachment = Attachment.objects.create(title=revision.title)
  revision.attachment = attachment
  revision.save()
  attachment.attach(document, request.user, revision)
  return redirect(document.get_edit_url())
 else:
  context = {'form': form, 'document': document}
  return render(request, 'attachments/edit_attachment.html', context)

@ xframe_options_sameorigin @ login_required @ process_document_path def edit_attachment ( request , document_slug , document_locale ) : document = get_object_or_404 ( Document , locale = document_locale , slug = document_slug ) if ( request . method != 'POST' ) : return redirect ( document . get_edit_url ( ) ) if ( not allow_add_attachment_by ( request . user ) ) : raise PermissionDenied form = AttachmentRevisionForm ( data = request . POST , files = request . FILES ) if form . is_valid ( ) : revision = form . save ( commit = False ) revision . creator = request . user attachment = Attachment . objects . create ( title = revision . title ) revision . attachment = attachment revision . save ( ) attachment . attach ( document , request . user , revision ) return redirect ( document . get_edit_url ( ) ) else : context = { 'form' : form , 'document' : document } return render ( request , 'attachments/edit_attachment.html' , context )
create a new attachment object and populate its initial revision or show a separate form view that allows to fix form submission errors .