annotate contact/views.py @ 943:cf9918328c64

Haystack tweaks for Django 1.7.7. I had to upgrade to Haystack 2.3.1 to get it to work with Django 1.7.7. I also had to update the Xapian backend. But I ran into problems. On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms are greater than 245 chars (or something) when indexing. So I created a custom field that would simply omit terms greater than 64 chars and used this field everywhere I previously used a CharField. Secondly, the custom search form was broken now. Something changed in the Xapian backend and exact searches stopped working. Fortunately the auto_query (which I was using originally and broke during an upgrade) started working again. So I cut the search form back over to doing an auto_query. I kept the form the same (3 fields) because I didn't want to change the form and I think it's better that way.
author Brian Neal <bgneal@gmail.com>
date Wed, 13 May 2015 20:25:07 -0500
parents 38db6ec61af3
children 6ac56115e0a8
rev   line source
bgneal@819 1 """Views for the contact application."""
gremmie@1 2
bgneal@819 3 from django.shortcuts import redirect, render
gremmie@1 4
gremmie@1 5 from contact.forms import ContactForm
gremmie@1 6 from core.functions import get_full_name
gremmie@1 7
gremmie@1 8
gremmie@1 9 def contact_form(request):
bgneal@819 10 if request.method == 'POST':
bgneal@819 11 form = ContactForm(request.POST)
bgneal@819 12 if form.is_valid():
bgneal@819 13 form.save()
bgneal@819 14 return redirect('contact-thanks')
bgneal@819 15 else:
bgneal@819 16 initial_data = {}
bgneal@819 17 if request.user.is_authenticated():
bgneal@819 18 name = get_full_name(request.user)
bgneal@819 19 initial_data = {'name': name, 'email': request.user.email}
gremmie@1 20
bgneal@819 21 subject = request.GET.get('subject')
bgneal@819 22 if subject:
bgneal@819 23 initial_data['subject'] = subject
gremmie@1 24
bgneal@819 25 form = ContactForm(initial=initial_data)
gremmie@1 26
bgneal@819 27 return render(request, 'contact/contact_form.html', {'form': form})