X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/a55d79e4c27c893841712145e38d4a4a61e04b20..9deec10bf95b8c5ad82eae80df832caef67b75e9:/contact/views.py diff --git a/contact/views.py b/contact/views.py index 5d4a62a..277d049 100644 --- a/contact/views.py +++ b/contact/views.py @@ -1,22 +1,33 @@ +from urllib import unquote from django.contrib.auth.decorators import permission_required from django.http import Http404, HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.utils.translation import ugettext_lazy as _ -from prawokultury.helpers import serve_file +from fnpdjango.utils.views import serve_file from .forms import contact_forms -from .models import Attachment +from .models import Attachment, Contact -def form(request, form_tag): +def form(request, form_tag, key=None): try: form_class = contact_forms[form_tag] except KeyError: raise Http404 if request.method == 'POST': - form = form_class(request.POST, request.FILES) + form = form_class(request.POST, request.FILES, key=key) if form.is_valid(): form.save(request) return redirect('contact_thanks', form_tag) + elif key: + try: + c = Contact.objects.get(form_tag=form_class.save_as_tag, key=key) + except Contact.DoesNotExist: + raise Http404 + initial = dict(c.body) + initial['contact'] = c.contact + for att in c.attachment_set.all(): + initial[att.tag] = att.file + form = form_class(initial=initial, key=key) else: form = form_class() return render(request, @@ -37,4 +48,4 @@ def thanks(request, form_tag): @permission_required('contact.change_attachment') def attachment(request, contact_id, tag): attachment = get_object_or_404(Attachment, contact_id=contact_id, tag=tag) - return serve_file(attachment.file.url) + return serve_file(unquote(attachment.file.url))