1 from django.contrib.auth.decorators import permission_required
2 from django.http import Http404, HttpResponse
3 from django.shortcuts import get_object_or_404, redirect, render
4 from django.utils.translation import ugettext_lazy as _
5 from prawokultury.helpers import serve_file
6 from .forms import contact_forms
7 from .models import Attachment
10 def form(request, form_tag):
12 form_class = contact_forms[form_tag]
15 if request.method == 'POST':
16 form = form_class(request.POST, request.FILES)
19 return redirect('contact_thanks', form_tag)
22 return render(request,
23 ['contact/%s/form.html' % form_tag, 'contact/form.html'],
28 def thanks(request, form_tag):
29 if form_tag not in contact_forms:
32 return render(request,
33 ['contact/%s/thanks.html' % form_tag, 'contact/thanks.html']
37 @permission_required('contact.change_attachment')
38 def attachment(request, contact_id, tag):
39 attachment = get_object_or_404(Attachment, contact_id=contact_id, tag=tag)
40 return serve_file(attachment.file.url)