cote = forms.CharField(required=False, label=('Cote'), widget=forms.TextInput(attrs={'type': 'search'}))
location = forms.CharField(required=False, label=('Location'), widget=forms.TextInput(attrs={'type': 'search'}))
+
def search(self):
sqs = SearchQuerySet().load_all()
if not self.is_valid():
- return sqs
+ return self.no_query_found()
- if self.cleaned_data['q']:
- sqs = sqs.filter(content__title__contains=self.cleaned_data['q'])
+ if self.cleaned_data.get('q'):
+ sqs = sqs.filter(title__title__contains=self.cleaned_data['q'])
- if self.cleaned_data['cote']:
- sqs = sqs.filter(content__cote__contains=self.cleaned_data['cote'])
+ if self.cleaned_data.get('cote'):
+ sqs = sqs.filter(cote__cote__contains=self.cleaned_data['cote'])
- if self.cleaned_data['location']:
- sqs = sqs.filter(content__title__contains=self.cleaned_data['location'])
+ if self.cleaned_data.get('location'):
+ sqs = sqs.filter(location__location__contains=self.cleaned_data['location'])
return sqs
\ No newline at end of file
urlpatterns = patterns('',
url(r'^$', HaystackSearch(), name='haystack_search'),
url(r'^quick/(?P<type>[A-Za-z0-9._-]+)/$', HaystackSearch(), name='haystack_search_type'),
- url(r'^advance/$', HaystackAdvanceSearch(template='search/advanceSearch.html'), name='haystack_advance_search'),
- url(r'^advance/(?P<type>[A-Za-z0-9._-]+)/$', HaystackAdvanceSearch(template='search/advanceSearch.html'), name='haystack_advance_search_type'),
-
+ url(r'^advance/$', HaystackAdvanceSearch(form_class=HayAdvanceForm, template='search/advanceSearch.html'), name='haystack_advance_search'),
+ url(r'^advance/(?P<type>[A-Za-z0-9._-]+)/$', HaystackAdvanceSearch(form_class=HayAdvanceForm, template='search/advanceSearch.html'), name='haystack_advance_search_type'),
)
text = indexes.CharField(document=True, use_template=True)
item_acces = indexes.CharField(model_attr= 'collection__public_access' , faceted=True)
item_status = indexes.CharField(model_attr= 'collection__document_status' , faceted=True)
+ title = indexes.NgramField(model_attr='title')
+ code = indexes.NgramField(model_attr='code')
+ location = indexes.NgramField(model_attr='location__name', default='')
def get_model(self):
return MediaItem
text = indexes.NgramField(document=True, use_template=True)
#rec_date = indexes.DateTimeField(use_template=True, null=True)
+ title = indexes.NgramField(model_attr='title')
+ code = indexes.NgramField(model_attr='code')
+ location = indexes.NgramField(default='')
def get_model(self):
- return MediaCollection
\ No newline at end of file
+ return MediaCollection
+
+ def prepare_location(self, obj):
+ return "%s" % obj.countries()
\ No newline at end of file
{% if query %}
<h1>{% trans "Results" %}</h1>
{% ifequal type 'item' %}
- <p><b>Items ({{item_count}}) | <a href="{% url "haystack_advance_search_type" "collection" %}?q={{ query }}&cote={{ cote }}&location={{ location}}&page=1">Collections ({{collection_count}})</a></b></p>
+ <p><b>Items ({{item_count}}) | <a href="{% url "haystack_advance_search_type" "collection" %}?q={{ query.q }}&cote={{ query.cote }}&location={{ query.location}}&page=1">Collections ({{collection_count}})</a></b></p>
{% else %}
{% ifequal type 'collection'%}
- <p><b><a href="{% url "haystack_advance_search_type" "item" %}?q={{ query }}&cote={{ cote }}&location={{ location}}&page=1">Items ({{item_count}}) </a>| Collections ({{collection_count}})</b></p>
+ <p><b><a href="{% url "haystack_advance_search_type" "item" %}?q={{ query.q }}&cote={{ query.cote }}&location={{ query.location}}&page=1">Items ({{item_count}}) </a>| Collections ({{collection_count}})</b></p>
{% endifequal %}
{% endifequal %}
{% with object_list as items %}
{% if page.has_previous or page.has_next %}
<div>
- {% if page.has_previous %}<a href="?q={{ query }}&cote={{ cote }}&location={{ location}}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
+ {% if page.has_previous %}<a href="?q={{ query.q }}&cote={{ query.cote }}&location={{ query.location}}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
|
- {% if page.has_next %}<a href="?q={{ query }}&cote={{ cote }}&location={{ location}}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
+ {% if page.has_next %}<a href="?q={{ query.q }}&cote={{ query.cote }}&location={{ query.location}}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% endwith %}
{{ object.archiver_notes }}
{{ object.items_done }}
{{ object.conservation_site }}
+{{ object.location }}
{{ object.body }}
def __call__(self, request, type=None):
self.type = type
- """if(self.type == 'collection'):
- self.form_class = HayAdvanceFormCollection
- else:
- self.form_class = HayAdvanceFormItem"""
- self.form_class = HayAdvanceForm
return super(HaystackAdvanceSearch, self).__call__(request)
+ def get_query(self):
+ """
+ Returns the query provided by the user.
+
+ Returns an empty string if the query is invalid.
+ """
+ if self.form.is_valid():
+ return self.form.cleaned_data
+
+ return ''
+
def get_results(self):
if(self.type == 'collection'):
return self.form.search().models(MediaCollection)