--- /dev/null
+from django.conf import settings
+import datetime
+from haystack import indexes
+from events.models import Event
+from migdal.helpers import add_translatable_index
+
+
+class EventIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
+ def get_model(self):
+ return Event
+
+ def index_queryset(self):
+ """Used when the entire index for model is updated."""
+ return self.get_model().objects.all()
+
+
+add_translatable_index(EventIndex, {
+# Haystack needs a main field to be the same across all indexes
+# so we treat title of the event as this main content, named 'body'
+ 'body': indexes.CharField(model_attr='title'),
+ 'organizer': indexes.CharField(),
+ 'place': indexes.CharField()
+ })
+
+
+getattr(EventIndex, "body_%s" % settings.LANGUAGE_CODE).document = True
+
{% extends "base.html" %}
{% load url from future %}
{% load i18n pagination_tags prevnext %}
+{% load events_tags %}
{% block "body" %}
<h1>{% trans "Events" %}</h1>
{% autopaginate object_list 10 %}
{% for event in object_list %}
- <div class="event">
- <a href="{{ event.link }}">
- <h2>{{ event.date }}</h2>{# just date #}
- <strong class="title">{{ event.title }}</strong>
-
- <div class="description">
- {{ event.date }}, {{ event.place }}<br/>
- {% trans "Organizer" %}: {{ event.organizer }}<br/>
- </div>
- </a>
- </div>
+ {% event_short event %}
{% endfor %}
<p class="prevnext">
{% endif %}
</p>
-{% endblock %}
\ No newline at end of file
+{% endblock %}
--- /dev/null
+{% load i18n %}
+ <div class="event">
+ <a href="{{ event.link }}">
+ <h2>{{ event.date }}</h2>{# just date #}
+ <strong class="title">{{ event.title }}</strong>
+
+ <div class="description">
+ {{ event.date }}, {{ event.place }}<br/>
+ {% trans "Organizer" %}: {{ event.organizer }}<br/>
+ </div>
+ </a>
+ </div>
+
def events_box(context, limit=app_settings.BOX_LENGTH):
objects = Event.objects.filter(date__gte=datetime.now())[:limit]
return {'objects': objects}
+
+
+@register.inclusion_tag('events/snippets/event_short.html')
+def event_short(event):
+ return {'event': event}
return pattern_list
return pattern_list + [MyLocaleRegexURLResolver(pattern_list)]
+
+def add_translatable_index(index_class, fields, languages=None):
+ """Adds some translatable fields to a search index, and a getter."""
+ if languages is None:
+ languages = settings.LANGUAGES
+ for name, field in fields.items():
+ for lang_code, lang_name in languages:
+ new_field = copy(field)
+ fname = "%s_%s" % (name, lang_code)
+ new_field.index_fieldname = new_field.index_fieldname \
+ and "%s_%s" % (new_field.index_fieldname, lang_code) \
+ or fname
+ new_field.model_attr = new_field.model_attr \
+ and "%s_%s" % (new_field.model_attr, lang_code) \
+ or fname
+ setattr(index_class, fname, new_field)
+ index_class.fields[fname] = new_field
+
import datetime
from haystack import indexes
from migdal.models import Entry
+from migdal.helpers import add_translatable_index
-from copy import copy
-
-class EntryIndex(indexes.SearchIndex, indexes.Indexable):
+class EntryIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
date = indexes.DateTimeField(indexed=True, model_attr="date")
author = indexes.CharField(model_attr="author")
return self.get_model().objects.filter(date__lte=datetime.datetime.now())
-def add_translatable(index_class, fields, languages=None):
- """Adds some translatable fields to a search index, and a getter."""
- if languages is None:
- languages = settings.LANGUAGES
- for name, field in fields.items():
- for lang_code, lang_name in languages:
- new_field = copy(field)
- fname = "%s_%s" % (name, lang_code)
- new_field.index_fieldname = fname
- new_field.model_attr = fname
- setattr(index_class, fname, new_field)
- index_class.fields[fname] = new_field
-
-
-add_translatable(EntryIndex, {
- 'title': indexes.CharField(indexed=True, document=False),
- 'lead': indexes.CharField(indexed=True, document=False),
- 'body': indexes.CharField(indexed=True, document=False)
+add_translatable_index(EntryIndex, {
+ 'title': indexes.CharField(),
+ 'lead': indexes.CharField(),
+ 'body': indexes.CharField()
})
{% load url from future %}
{% load i18n %}
{% load migdal_tags %}
+{% load events_tags %}
{% block "body" %}
<h1>{% trans "Search results" %}</h1>
{% for result in page.object_list %}
-{% entry_short result.object %}
+ {% if result.model_name == "entry" %}
+ {% entry_short result.object %}
+ {% elif result.model_name == "event" %}
+ {% event_short result.object %}
+ {% endif %}
{% empty %}
<p>{% trans "No results found." %}</p>
{% endfor %}
from migdal.helpers import i18n_patterns
from migdal.urls import urlpatterns as migdal_urlpatterns
from django.utils.translation import ugettext_lazy as _, string_concat
-
+from events.urls import urlpatterns as events_urlpatterns
admin.autodiscover()
) + i18n_patterns('',
url(string_concat(r'^', _('events'), r'/'), include('events.urls')),
url(r'^comments/', include('django_comments_xtd.urls')),
-) + migdal_urlpatterns
+) + migdal_urlpatterns
if settings.DEBUG:
urlpatterns += patterns('',