1 from urllib import unquote
2 from django.contrib.auth.decorators import permission_required
3 from django.http import Http404, HttpResponse
4 from django.shortcuts import get_object_or_404, redirect, render
5 from django.utils.translation import ugettext_lazy as _
6 from fnpdjango.utils.views import serve_file
7 from .forms import contact_forms
8 from .models import Attachment
11 def form(request, form_tag):
13 form_class = contact_forms[form_tag]
16 if request.method == 'POST':
17 form = form_class(request.POST, request.FILES)
20 return redirect('contact_thanks', form_tag)
23 return render(request,
24 ['contact/%s/form.html' % form_tag, 'contact/form.html'],
29 def thanks(request, form_tag):
30 if form_tag not in contact_forms:
33 return render(request,
34 ['contact/%s/thanks.html' % form_tag, 'contact/thanks.html']
38 @permission_required('contact.change_attachment')
39 def attachment(request, contact_id, tag):
40 attachment = get_object_or_404(Attachment, contact_id=contact_id, tag=tag)
41 return serve_file(unquote(attachment.file.url))