Commits

Frank Becker committed aa22064

merge back search changes from upstream page

  • Participants
  • Parent commits 9204e89

Comments (0)

Files changed (4)

File src/pentasubmitter/search_sites.py

 """Search using Haystack"""
 
 import haystack
+from haystack import site, indexes
+import datetime
+from submitter.models import NewsEntry
+from show.models import PentaShow
+__author__ = 'a8'
 
-haystack.autodiscover()
+#haystack.autodiscover()
 
-# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 :
+class NewsEntryIndex(indexes.SearchIndex):
+    text = indexes.CharField(document=True, use_template=True)
+    #author = indexes.CharField(model_attr='user')
+    submit_date = indexes.DateTimeField(model_attr='submit_date')
+    excerpt = indexes.CharField(model_attr='excerpt')
 
+    #def index_queryset(self):
+    #    """Used when the entire index for model is updated."""
+    #    return NewsEntry.objects.all().order_by('-pub_date')
+
+
+site.register(NewsEntry, NewsEntryIndex)
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8 :

File src/pentasubmitter/urls.py

 from django.conf import settings
 from django.views.generic.simple import redirect_to, direct_to_template
 from django.conf.urls.defaults import *
+from haystack.views import SearchView
+from haystack.query import SearchQuerySet
 
 # The next two lines enable the admin and load each admin.py file:
 from django.contrib import admin
      {'template': 'nojavascripthere.html'}),
 )
 
+
+sqs = SearchQuerySet().order_by('-submit_date')
 urlpatterns += patterns(
     '',
     (r'^account/user.html$', 'pentasubmitter.views.user_account_management'),
     #(r'^profiles/', include('profiles.urls')),
     (r'^submit/', include('submitter.urls')),
     (r'^show/', include('show.urls')),
-    (r'^search/', include('haystack.urls')),
+#    (r'^search/', include('haystack.urls')),
+	url(r'^search/', SearchView(load_all=False,  searchqueryset=sqs),  
+			name='haystack_search',  
+	   ),  
 
     # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
     # to INSTALLED_APPS to enable admin documentation:

File src/submitter/urls.py

 """
 
 from django.conf.urls.defaults import patterns, url
+from django.http import Http404
 from django.views.generic.simple import redirect_to, direct_to_template
 from django.utils.translation import ugettext_lazy as _
 #from django.views.generic.simple import direct_to_template
 from submitter.models import EntryCategory, NewsEntry
 from submitter.feeds import LatestNewsEntries, CurrentShowNewsEntries, \
         LatestPentaShows, NewsEntriesPerShow
+from submitter.views import get_next_shows
+
+# get next show for redirect
+next_shows = get_next_shows()
+if not next_shows:
+    raise Http404
+penta_show_slug = next_shows[0].slug
 
 urlpatterns = patterns(
     '',
     #('^$', redirect_to, {'url': 'last/'}),
-    ('^$', redirect_to, {'url': 'news-per-next-show/'}),
+    ('^$', redirect_to, {'url': 'news-per-show/' + penta_show_slug}),
 )
 
 news_entry_info_dict = dict(

File src/submitter/views.py

 def news_per_show(request, show_slug=None):
     """Return HTTP response of all NewsEntry() per PentaShow()"""
 
-    penta_show = get_object_or_404(
-        PentaShow,
-        slug__iexact=show_slug
-    )
+    if not show_slug:
+        next_shows = get_next_shows()
+        if not next_shows:
+            raise Http404
+        penta_show = next_shows[0]
+    else:
+        penta_show = get_object_or_404(
+            PentaShow,
+            slug__iexact=show_slug
+        )
     filters = {'show': penta_show, 'status': 1}
     return list_detail.object_list(
         request,