]> git.parisson.com Git - telemeta.git/commitdiff
Advance Search initialize with title, cote and location
authorKaltar5679 <killian.mary@outlook.fr>
Tue, 28 Apr 2015 10:19:35 +0000 (12:19 +0200)
committerKaltar5679 <killian.mary@outlook.fr>
Tue, 28 Apr 2015 10:19:35 +0000 (12:19 +0200)
telemeta/forms/haystack_form.py
telemeta/haystack_urls.py
telemeta/search_indexes.py
telemeta/templates/search/advanceSearch.html
telemeta/templates/search/indexes/telemeta/mediacollection_text.txt
telemeta/views/haystack_search.py

index b8700a6beee3753f26f53fc3b18c272901af0a23..f28688d16a370b997fda1ae7efb6786ffd695c98 100644 (file)
@@ -74,19 +74,20 @@ class HayAdvanceForm(SearchForm):
     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
index 503b6a02a7dfc199671e7bb14619e21b59d87f67..974ce2c85df60cdf0a635db9137efc594a27f4b2 100644 (file)
@@ -7,7 +7,6 @@ from haystack.forms import *
 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'),
 )
index ae7e95bf5a57a187c005988607b5d78c58213e23..70b610f1a2d0da4a5269e9097ed1d0e791d05d8a 100644 (file)
@@ -7,6 +7,9 @@ class MediaItemIndex(indexes.SearchIndex, indexes.Indexable):
     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
@@ -16,6 +19,12 @@ class MediaCollectionIndex(indexes.SearchIndex, indexes.Indexable):
 
     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
index 5d1abd60fa924c190fbf5d830f9471f4eee3b523..93fed0610dd2351a8d76c8ed7e2e2f55c721ded7 100644 (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}}&amp;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}}&amp;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}}&amp;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}}&amp;page=1">Items ({{item_count}}) </a>| Collections ({{collection_count}})</b></p>
                 {% endifequal %}
              {% endifequal %}
              {% with object_list as items %}
@@ -35,9 +35,9 @@
 
                 {% if page.has_previous or page.has_next %}
                     <div>
-                        {% if page.has_previous %}<a href="?q={{ query }}&cote={{ cote }}&location={{ location}}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
+                        {% if page.has_previous %}<a href="?q={{ query.q }}&cote={{ query.cote }}&location={{ query.location}}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
                         |
-                        {% if page.has_next %}<a href="?q={{ query }}&cote={{ cote }}&location={{ location}}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
+                        {% if page.has_next %}<a href="?q={{ query.q }}&cote={{ query.cote }}&location={{ query.location}}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
                     </div>
                 {% endif %}
             {% endwith %}
index 9cea4c460f58ee1fabd02d861d99d4847c7fe161..e41993c24cedea9c102d9f757ad8da4861e9623f 100644 (file)
@@ -13,4 +13,5 @@
 {{ object.archiver_notes }}
 {{ object.items_done }}
 {{ object.conservation_site }}
+{{ object.location }}
 {{ object.body }}
index 28022c4798c64a9cb3afff01d312d335f9b0b794..7dd303fbae8184b2f216308b123f5fc0680b9af4 100644 (file)
@@ -35,13 +35,19 @@ class HaystackAdvanceSearch(SearchView):
 
     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)