]> git.parisson.com Git - telemeta.git/commitdiff
fix quick search ; advanced search : fix searching by collector, creator and publish...
authorolivier <>
Mon, 15 Feb 2010 16:56:17 +0000 (16:56 +0000)
committerolivier <>
Mon, 15 Feb 2010 16:56:17 +0000 (16:56 +0000)
telemeta/htdocs/css/telemeta.css
telemeta/locale/fr/LC_MESSAGES/django.mo
telemeta/locale/fr/LC_MESSAGES/django.po
telemeta/models/__init__.py
telemeta/models/core.py
telemeta/models/query.py
telemeta/templates/telemeta_default/inc/collection_list.html
telemeta/templates/telemeta_default/inc/mediaitem_list.html
telemeta/templates/telemeta_default/search_criteria.html
telemeta/templates/telemeta_default/search_results.html
telemeta/web/base.py

index 5770da991518fdfed191ab1a1ba9918708dc2a5e..a5c3b6382f28d92b4b785306431ed35041e6b763 100644 (file)
@@ -254,7 +254,7 @@ label.disabled { color: #d7d7d7 }
 #searchform fieldset {\r
     padding: 0;\r
     padding: .5em;\r
-    width: 450px;\r
+    width: 650px;\r
     border: none;\r
     border: 1px dotted #888;\r
     margin-bottom: 1em;\r
index 5ed08461c97097020302dcc31c78c6fb99ed7f76..e42705f9e641a4d50f59a91863e24d1b863284c1 100644 (file)
Binary files a/telemeta/locale/fr/LC_MESSAGES/django.mo and b/telemeta/locale/fr/LC_MESSAGES/django.mo differ
index a8eb303590942ac6dfb4c6f1eb3c3761977ac5b5..a7247051f174f07d647622c55f9c12734b39ee3e 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-02-12 14:31+0100\n"
+"POT-Creation-Date: 2010-02-15 17:49+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: Olivier Guilyardi <olivier samalyse com>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -32,13 +32,13 @@ msgstr "valeur"
 msgid "publisher"
 msgstr "éditeur"
 
-#: models/enum.py:134 models/enum.py:145 models/instrument.py:41
+#: models/enum.py:134 models/enum.py:146 models/instrument.py:41
 #: models/instrument.py:51 models/location.py:50 models/location.py:142
 #: models/media.py:347
 msgid "name"
 msgstr "nom"
 
-#: models/enum.py:144 models/media.py:225
+#: models/enum.py:138 models/enum.py:145 models/media.py:225
 msgid "population / social group"
 msgstr "population / groupe social"
 
@@ -78,7 +78,7 @@ msgstr "type complet"
 msgid "current location"
 msgstr "lieu actuel"
 
-#: models/location.py:57 models/location.py:151
+#: models/location.py:57 models/location.py:151 models/location.py:165
 msgid "authoritative"
 msgstr "officiel"
 
@@ -428,6 +428,7 @@ msgid "Search"
 msgstr "Recherche"
 
 #: templates/telemeta_default/base.html:34
+#: templates/telemeta_default/search_criteria.html:53
 msgid "Advanced search"
 msgstr "Recherche avancée"
 
@@ -473,8 +474,8 @@ msgid "Legal mentions"
 msgstr "Mentions légales"
 
 #: templates/telemeta_default/collection_detail.html:77
-#: templates/telemeta_default/inc/collection_list.html:16
-#: templates/telemeta_default/inc/mediaitem_list.html:15
+#: templates/telemeta_default/inc/collection_list.html:17
+#: templates/telemeta_default/inc/mediaitem_list.html:16
 msgid "Recordist"
 msgstr "Enregistré par"
 
@@ -528,7 +529,7 @@ msgid "List"
 msgstr "Liste"
 
 #: templates/telemeta_default/geo_continents.html:24
-#: templates/telemeta_default/index.html:8
+#: templates/telemeta_default/index.html:9
 msgid "Geographic Navigator"
 msgstr "Navigateur géographique"
 
@@ -538,11 +539,11 @@ msgstr "Navigateur géographique"
 msgid "World"
 msgstr "Monde"
 
-#: templates/telemeta_default/index.html:10
+#: templates/telemeta_default/index.html:11
 msgid "Open the geographic navigator"
 msgstr "Accéder au navigateur géographique"
 
-#: templates/telemeta_default/index.html:13
+#: templates/telemeta_default/index.html:14
 msgid "Musical selection"
 msgstr "Sélection musicale"
 
@@ -551,7 +552,7 @@ msgid "Recording date"
 msgstr "Date d'enregistrement"
 
 #: templates/telemeta_default/mediaitem_detail.html:147
-#: templates/telemeta_default/inc/mediaitem_list.html:17
+#: templates/telemeta_default/inc/mediaitem_list.html:18
 msgid "Location"
 msgstr "Lieu"
 
@@ -567,22 +568,50 @@ msgstr "Informations générales"
 msgid "No such item"
 msgstr "Item introuvable"
 
-#: templates/telemeta_default/inc/collection_list.html:6
-#, python-format
-msgid "Collections %(first_on_page)s to %(last_on_page)s on %(hits)s"
-msgstr "Collections %(first_on_page)s à %(last_on_page)s sur %(hits)s"
-
+#: templates/telemeta_default/search_criteria.html:87
 #: templates/telemeta_default/inc/collection_list.html:14
 #: templates/telemeta_default/inc/mediaitem_list.html:14
 msgid "Title"
 msgstr "Titre"
 
-#: templates/telemeta_default/inc/collection_list.html:17
-#: templates/telemeta_default/inc/mediaitem_list.html:21
+#: templates/telemeta_default/search_criteria.html:93
+#: templates/telemeta_default/search_results.html:29
+#: templates/telemeta_default/inc/collection_list.html:18
+#: templates/telemeta_default/inc/mediaitem_list.html:22
 msgid "Year of recording"
 msgstr "Année d'enregistrement"
 
-#: templates/telemeta_default/inc/collection_list.html:38
+#: templates/telemeta_default/search_criteria.html:100
+#: templates/telemeta_default/search_criteria.html:119
+#: templates/telemeta_default/search_results.html:31
+#: templates/telemeta_default/search_results.html:38
+msgid "to"
+msgstr "à"
+
+#: templates/telemeta_default/search_criteria.html:112
+#: templates/telemeta_default/search_results.html:36
+msgid "Year of issue"
+msgstr "Année de parution"
+
+#: templates/telemeta_default/search_results.html:6
+msgid "Search results"
+msgstr "Résultats de recherche"
+
+#: templates/telemeta_default/search_results.html:11
+msgid "Search pattern"
+msgstr "Recherche"
+
+#: templates/telemeta_default/inc/collection_list.html:6
+#, python-format
+msgid "Collections %(first_on_page)s to %(last_on_page)s on %(hits)s"
+msgstr "Collections %(first_on_page)s à %(last_on_page)s sur %(hits)s"
+
+#: templates/telemeta_default/inc/collection_list.html:15
+#: templates/telemeta_default/inc/mediaitem_list.html:15
+msgid "Code"
+msgstr "Cote"
+
+#: templates/telemeta_default/inc/collection_list.html:42
 msgid "No collection"
 msgstr "Aucune collection"
 
@@ -595,22 +624,22 @@ msgstr "Métadonnées Dublin Core"
 msgid "Items %(first_on_page)s to %(last_on_page)s on %(hits)s"
 msgstr "Items %(first_on_page)s à %(last_on_page)s sur %(hits)s"
 
-#: templates/telemeta_default/inc/mediaitem_list.html:19
+#: templates/telemeta_default/inc/mediaitem_list.html:20
 msgid "Country/Continent"
 msgstr "Pays/Continent"
 
-#: templates/telemeta_default/inc/mediaitem_list.html:46
+#: templates/telemeta_default/inc/mediaitem_list.html:50
 msgid "No item"
 msgstr "Aucun item"
 
-#: templatetags/telemeta_utils.py:200
+#: templatetags/telemeta_utils.py:203
 #, python-format
 msgid "%(count)d item"
 msgid_plural "%(count)d items"
 msgstr[0] "%(count)d item"
 msgstr[1] "%(count)d items"
 
-#: templatetags/telemeta_utils.py:203
+#: templatetags/telemeta_utils.py:206
 #, python-format
 msgid "%(count)d collection"
 msgid_plural "%(count)d collections"
index 678ec369295f671c65f5dcd7fdfd584ef33fd659..5dd06929e4edbe0a8a8254aa4cafd21723ad024b 100644 (file)
@@ -37,6 +37,4 @@ from telemeta.models.location import *
 from telemeta.models.instrument import *
 from telemeta.models.enum import *
 from telemeta.models.system import *
-#MediaCollection, MediaItem, MediaPart,  Revision, \
-#    PhysicalFormat, PublishingStatus
 
index 0fc8d62e968e83acee30df7564bf69464283ec34..7db1716cb5e0da69d37de44b1060fd4afb1261df 100644 (file)
@@ -36,7 +36,7 @@
 __all__ = ['ModelCore', 'MetaCore', 'DurationField', 'Duration', 'WeakForeignKey', 
            'EnhancedModel', 'CharField', 'TextField', 'IntegerField', 'BooleanField', 
            'DateTimeField', 'FileField', 'ForeignKey', 'FloatField', 'DateField',
-           'RequiredFieldError', 'CoreQuerySet', 'CoreManager']
+           'RequiredFieldError', 'CoreQuerySet', 'CoreManager', 'word_search_q']
 
 from django.core import exceptions
 from django import forms
@@ -410,6 +410,16 @@ class ModelCore(EnhancedModel):
 class MetaCore:
     app_label = 'telemeta'
 
+def word_search_q(field, pattern):
+    words = re.split("[ .*-]+", pattern)
+    q = Q()
+    for w in words:
+        if len(w) >= 3:
+            kwargs = {field + '__icontains': w}
+            q &= Q(**kwargs)
+
+    return q
+
 class CoreQuerySet(EnhancedQuerySet):
     "Base class for all query sets"
 
@@ -417,18 +427,8 @@ class CoreQuerySet(EnhancedQuerySet):
         "Return an empty result set"
         return self.extra(where = ["0 = 1"])
 
-    def word_search_q(self, field, pattern):
-        words = re.split("[ .*-]+", pattern)
-        q = Q()
-        for w in words:
-            if len(w) >= 3:
-                kwargs = {field + '__icontains': w}
-                q &= Q(**kwargs)
-
-        return q
-
     def word_search(self, field, pattern):
-        return self.filter(self.word_search_q(field, pattern))
+        return self.filter(word_search_q(field, pattern))
         
     def _by_change_time(self, type, from_time = None, until_time = None):
         "Search between two revision dates"
index 1f96d36ca938f832f3fda45d79ab39a800ba91b6..c46f31d46eca609e5a4d284545f770082d6fb3fa 100644 (file)
@@ -43,11 +43,13 @@ class MediaItemQuerySet(CoreQuerySet):
     "Base class for all media item query sets"
     
     def quick_search(self, pattern):
-        "Perform a quick search on id and title"
+        "Perform a quick search on code, title and collector name"
+        pattern = pattern.strip()
         return self.filter(
-            self.word_search_q('id', pattern) |
-            self.word_search_q('title', pattern) |  
-            self.word_search_q('author', pattern)   
+            Q(code__contains=pattern.strip()) |
+            Q(old_code__contains=pattern.strip()) |
+            word_search_q('title', pattern) |  
+            self.by_fuzzy_collector_q(pattern)
         )
 
     def without_collection(self):        
@@ -66,7 +68,8 @@ class MediaItemQuerySet(CoreQuerySet):
     def by_title(self, pattern):
         "Find items by title"
         # to (sort of) sync with models.media.MediaItem.get_title()
-        return self.filter(self.word_search_q("title", pattern) | self.word_search_q("collection__title", pattern))
+        return self.filter(word_search_q("title", pattern) | 
+                           (Q(title="") & word_search_q("collection__title", pattern)))
 
     def by_publish_year(self, from_year, to_year = None):
         "Find items by publishing year"
@@ -158,6 +161,15 @@ class MediaItemQuerySet(CoreQuerySet):
         ids = self.filter(ethnic_group__isnull=False).values('ethnic_group');
         return EthnicGroup.objects.filter(pk__in=ids).order_by('name')
 
+    @staticmethod
+    def by_fuzzy_collector_q(pattern):
+        return (word_search_q('collection__creator', pattern) | 
+                word_search_q('collection__collector', pattern) | 
+                word_search_q('collector', pattern))
+
+    def by_fuzzy_collector(self, pattern):
+        return self.filter(self.by_fuzzy_collector_q(pattern))
+
 class MediaItemManager(CoreManager):
     "Manage media items queries"
 
@@ -200,11 +212,13 @@ class MediaItemManager(CoreManager):
 class MediaCollectionQuerySet(CoreQuerySet):
 
     def quick_search(self, pattern):
-        "Perform a quick search on id, title and creator name"
+        "Perform a quick search on code, title and collector name"
+        pattern = pattern.strip()
         return self.filter(
-            self.word_search_q('id', pattern) |
-            self.word_search_q('title', pattern) |  
-            self.word_search_q('creator', pattern)   
+            Q(code__contains=pattern.strip()) |
+            Q(old_code__contains=pattern.strip()) |
+            word_search_q('title', pattern) |  
+            self.by_fuzzy_collector_q(pattern)
         )
 
     def by_location(self, location):
@@ -253,8 +267,26 @@ class MediaCollectionQuerySet(CoreQuerySet):
         to_min   = self.filter(recorded_to_year__gt=0).aggregate(Min('recorded_to_year'))['recorded_to_year__min']
         year_min = min(from_min, to_min) 
 
+        if not year_max:
+            year_max = year_min
+        elif not year_min:
+            year_min = year_max
+
+        return year_min, year_max
+
+    def publishing_year_range(self):
+        year_max = self.aggregate(Max('year_published'))['year_published__max']
+        year_min = self.filter(year_published__gt=0).aggregate(Min('year_published'))['year_published__min']
+
         return year_min, year_max
 
+    @staticmethod
+    def by_fuzzy_collector_q(pattern):
+        return word_search_q('creator', pattern) | word_search_q('collector', pattern)
+
+    def by_fuzzy_collector(self, pattern):
+        return self.filter(self.by_fuzzy_collector_q(pattern))
+
 class MediaCollectionManager(CoreManager):
     "Manage collection queries"
 
index a245cd9bcf0c6315ec07115294d61976f15ced80..8ff255a6d13dd7fcdf161e6c9d5d4870ab6f9c82 100644 (file)
@@ -12,6 +12,7 @@
 <table class="listing">
 <tr>
     <th class="highlight">{% trans "Title" %}</th>
+    <th>{% trans "Code" %}</th>
     <th>{% field_label "MediaCollection" "creator" %}</th>
     <th>{% trans "Recordist" %}</th>
     <th>{% trans "Year of recording" %}</th>
@@ -21,6 +22,9 @@
     <td class="highlight">
         <a href="{% url telemeta-collection-detail collection.public_id %}">{{ collection }}</a>
     </td>
+    <td>
+        {{ collection.code|default:collection.old_code }}
+    </td>
     <td>{{ collection.creator }}</td>
     <td>{{ collection.apparent_collector }}</td>
     <td>
index 67a1570ba19bb671919811172b25196a22b68bb0..4bae20a852ed4177c5784530afd27bb993aac3e4 100644 (file)
@@ -12,6 +12,7 @@
 <table class="listing">
 <tr>
     <th class="highlight">{% trans "Title" %}</th>
+    <th>{% trans "Code" %}</th>
     <th>{% trans "Recordist" %}</th>
     {% if location_name %}
     <th>{% trans "Location" %}</th>
@@ -25,6 +26,9 @@
     <td class="highlight">
         <a href="{% url telemeta-item-detail item.public_id %}">{{ item }}</a>
     </td>
+    <td>
+        {{ item.code|default:item.old_code }}
+    </td>
     <td>{{ item.apparent_collector }}</td>
     {% if location_name %}
     <td>{{ item.location.name }}</td>
index d0e283360755e83c72d20ae93672c5231b42b205..a9b3f00b1c671c1c05f646669ab626f6d57e353c 100644 (file)
@@ -10,9 +10,9 @@
 {% block extra_javascript %}
 <script src="{% url telemeta-js "jquery.autocomplete.js" %}" type="text/javascript"></script>
 <script type="text/javascript">
-function update_rec_period() {
-    var from_year = $('#rec_year_from');
-    var to_year = $('#rec_year_to');
+function update_period(from_field, to_field) {
+    var from_year = $(from_field);
+    var to_year = $(to_field);
 
     if (from_year.val() == "0") {
         to_year.attr('disabled', '1');
@@ -36,15 +36,21 @@ $(document).ready(function () {
             return data[0].replace(/ *\([0-9]+.*\) *$/, '');
         }
     });
-    update_rec_period();
-    $('#rec_year_from, #rec_year_to').change(update_rec_period);
+    update_period('#rec_year_from', '#rec_year_to');
+    $('#rec_year_from, #rec_year_to').change(function () {
+        update_period('#rec_year_from', '#rec_year_to');
+    });
+    update_period('#pub_year_from', '#pub_year_to');
+    $('#pub_year_from, #pub_year_to').change(function () {
+        update_period('#pub_year_from', '#pub_year_to');
+    });
 });
 
 </script>
 {% endblock %}
 
 {% block content %}
-<h3>Advanced search</h3>
+<h3>{% trans "Advanced search" %}</h3>
 
 <form action="{% url telemeta-search %}" id="searchform">
 <fieldset>
@@ -68,18 +74,23 @@ $(document).ready(function () {
 <fieldset>
 
     <p>
-    <label for="creator">Creator</label>
+    <label for="title">{% trans "Title" %}</label>
+    <input type="text" id="title" name="title" />
+    </p>
+
+    <p>
+    <label for="creator">{% field_label "MediaCollection" "creator" %}</label>
     <input type="text" id="creator" name="creator" />
     </p>
 
     <p>
-    <label for="title">Title</label>
-    <input type="text" id="title" name="title" />
+    <label for="collector">{% field_label "MediaCollection" "collector" %}</label>
+    <input type="text" id="collector" name="collector" />
     </p>
 
     {% if rec_years %} 
     <p>
-    <label for="rec_date">{% trans "Year of recording" %}</label>
+    <label for="rec_date_from">{% trans "Year of recording" %}</label>
     <select id="rec_year_from" name="rec_year_from" class="tiny">
         <option value="0"></option>
         {% for year in rec_years %}
@@ -96,10 +107,24 @@ $(document).ready(function () {
     </p>
     {% endif %}
 
+    {% if pub_years %} 
     <p>
-    <label for="pub_date">Publishing date</label>
-    <input type="text" id="pub_date" name="pub_date" />
+    <label for="pub_date_from">{% trans "Year of issue" %}</label>
+    <select id="pub_year_from" name="pub_year_from" class="tiny">
+        <option value="0"></option>
+        {% for year in pub_years %}
+        <option value="{{ year }}" {% ifequal criteria.pub_year_from year %}selected {% endifequal %}>{{year}}</option>
+        {% endfor %}
+    </select>
+    {% trans "to" %}
+    <select id="pub_year_to" name="pub_year_to" class="tiny">
+        <option value="0"></option>
+        {% for year in pub_years %}
+        <option value="{{ year }}" {% ifequal criteria.pub_year_to year %}selected {% endifequal %}>{{year}}</option>
+        {% endfor %}
+    </select>
     </p>
+    {% endif %}
 
 </fieldset>
 
index 2d58402b550299fcfbeef4315a60772c4c498a46..2cca3157eaa074097583a34f098500dac409965a 100644 (file)
@@ -3,7 +3,7 @@
 {% load i18n %}
 
 {% block content %}
-<h3>Search results</h3>
+<h3>{% trans "Search results" %}</h3>
 
 {% if criteria %}
 <ul>
     <li><b>{% trans "Search pattern" %}:</b> {{criteria.pattern}}</li>
   {% endif %}
   {% if criteria.location %}
-    <li><b>{% field_label "Location" %}</b>: {{criteria.location}}</li>
+    <li><b>{% field_label "Location" %}:</b> {{criteria.location}}</li>
   {% endif %}
   {% if criteria.ethnic_group %}
     <li><b>{% field_label "EthnicGroup" %}:</b> {{criteria.ethnic_group}}</li>
   {% endif %}
   {% if criteria.creator %}
-    <li><b>Creator:</b> {{criteria.creator}}</li>
+    <li><b>{% field_label "MediaCollection" "creator" %}:</b> {{criteria.creator}}</li>
+  {% endif %}
+  {% if criteria.collector %}
+    <li><b>{% field_label "MediaCollection" "collector" %}:</b> {{criteria.collector}}</li>
   {% endif %}
   {% if criteria.title %}
     <li><b>Title:</b> {{criteria.title}}</li>
      {% endifnotequal %}
     </li>
   {% endif %}
-  {% if criteria.pub_date %}
-    <li><b>Publishing date:</b> {{criteria.pub_date}}</li>
+  {% if criteria.pub_year_from %}
+    <li><b>{% trans "Year of issue" %}:</b> {{criteria.pub_year_from}}
+     {% ifnotequal criteria.pub_year_to criteria.pub_year_from %}
+     {% trans "to" %} {{criteria.pub_year_to}}
+     {% endifnotequal %}
+    </li>
   {% endif %}
 </ul>
 {% endif %}
index 7a64f6a879d2b6a8428523229fe8b845f5432b59..c8b05f3fdf1fc08528895f990eeb99192b917333 100644 (file)
@@ -169,10 +169,12 @@ class WebView(Component):
 
     def edit_search(self, request, criteria=None):
         year_min, year_max = MediaCollection.objects.all().recording_year_range()
-        years = year_min and year_max and range(year_min, year_max + 1) \
-                or year_min and [year_min] or year_max and [year_max]
+        rec_years = year_min and year_max and range(year_min, year_max + 1) or []
+        year_min, year_max = MediaCollection.objects.all().publishing_year_range()
+        pub_years = year_min and year_max and range(year_min, year_max + 1) or []
         return render_to_response('telemeta/search_criteria.html', {
-            'rec_years': years,
+            'rec_years': rec_years,
+            'pub_years': pub_years,
             'ethnic_groups': MediaItem.objects.all().ethnic_groups(),
             'criteria': criteria
         })
@@ -218,20 +220,24 @@ class WebView(Component):
                 EthnicGroup.objects.get(pk=value)),
             'creator': lambda value: (
                 collections.word_search('creator', value),
-                items.word_search('auteur', value)),
+                items.word_search('collection__creator', value)),
+            'collector': lambda value: (
+                collections.by_fuzzy_collector(value),
+                items.by_fuzzy_collector(value)),
             'rec_year_from': lambda value: (
-                collections.by_recording_year(int(value), int(input['rec_year_to'])), 
+                collections.by_recording_year(int(value), int(input.get('rec_year_to', value))), 
                 items.by_recording_date(datetime.date(int(value), 1, 1), 
-                                        datetime.date(int(input['rec_year_to']), 12, 31))),
+                                        datetime.date(int(input.get('rec_year_to', value)), 12, 31))),
             'rec_year_to': lambda value: (collections, items),
-            'pub_date': lambda value: (
-                collections.by_publish_date(value), 
-                items.by_publish_date(value))
+            'pub_year_from': lambda value: (
+                collections.by_publish_year(int(value), int(input.get('pub_year_to', value))), 
+                items.by_publish_year(int(value), int(input.get('pub_year_to', value)))),
+            'pub_year_to': lambda value: (collections, items),
         }
        
         for key, value in input.items():
             func = switch.get(key)
-            if func and value:
+            if func and value and value != "0":
                 res = func(value)
                 if len(res) > 2:
                     collections, items, value = res
@@ -239,6 +245,8 @@ class WebView(Component):
                     collections, items = res
                 criteria[key] = value
 
+        print collections.query
+
         if type is None:
             if collections.count() and not items.count():
                 type = 'collections'