annotate ygroup/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 ee87ea74d46b
children 5d208c3321ce
rev   line source
bgneal@323 1 """
bgneal@323 2 Views for the ygroup (Yahoo Group Archive) application.
bgneal@323 3
bgneal@323 4 """
bgneal@323 5 from django.shortcuts import get_object_or_404
bgneal@323 6 from django.views.generic import ListView
bgneal@323 7
bgneal@323 8 from ygroup.models import Thread, Post
bgneal@323 9 from core.paginator import DiggPaginator
bgneal@323 10
bgneal@323 11
bgneal@323 12 THREADS_PER_PAGE = 40
bgneal@323 13 POSTS_PER_PAGE = 20
bgneal@323 14
bgneal@323 15
bgneal@323 16 class ThreadIndexView(ListView):
bgneal@323 17 """
bgneal@323 18 This generic view displays the list of threads available.
bgneal@323 19
bgneal@323 20 """
bgneal@323 21 model = Thread
bgneal@323 22 paginate_by = THREADS_PER_PAGE
bgneal@323 23
bgneal@323 24 def get_paginator(self, queryset, per_page, **kwargs):
bgneal@323 25 """
bgneal@323 26 Return an instance of the paginator for this view.
bgneal@323 27 """
bgneal@323 28 return DiggPaginator(queryset, per_page, body=5, tail=2,
bgneal@323 29 margin=3, padding=2, **kwargs)
bgneal@323 30
bgneal@323 31
bgneal@323 32 class ThreadView(ListView):
bgneal@323 33 """
bgneal@323 34 This generic view displays the posts in a thread.
bgneal@323 35
bgneal@323 36 """
bgneal@323 37 context_object_name = "post_list"
bgneal@323 38 template_name = "ygroup/thread.html"
bgneal@323 39 paginate_by = POSTS_PER_PAGE
bgneal@323 40
bgneal@323 41 def get_queryset(self):
bgneal@323 42 self.thread = get_object_or_404(Thread, pk=self.args[0])
bgneal@323 43 return Post.objects.filter(thread=self.thread)
bgneal@323 44
bgneal@323 45 def get_context_data(self, **kwargs):
bgneal@323 46 context = super(ThreadView, self).get_context_data(**kwargs)
bgneal@323 47 context['thread'] = self.thread
bgneal@323 48 return context
bgneal@323 49
bgneal@323 50 def get_paginator(self, queryset, per_page, **kwargs):
bgneal@323 51 """
bgneal@323 52 Return an instance of the paginator for this view.
bgneal@323 53 """
bgneal@323 54 return DiggPaginator(queryset, per_page, body=5, tail=2,
bgneal@323 55 margin=3, padding=2, **kwargs)