]> git.parisson.com Git - telemeta.git/commitdiff
fix searching by ethnic group
authorolivier <>
Mon, 15 Feb 2010 11:47:10 +0000 (11:47 +0000)
committerolivier <>
Mon, 15 Feb 2010 11:47:10 +0000 (11:47 +0000)
telemeta/models/enum.py
telemeta/models/query.py
telemeta/templates/telemeta_default/search_criteria.html
telemeta/templates/telemeta_default/search_results.html
telemeta/web/base.py

index 619a11d10f8ec39827b1abd6e793c3aa46ce5c5d..4d33bd100002acf4b6aa941c18daeb1c1f8810c8 100644 (file)
@@ -135,6 +135,7 @@ class EthnicGroup(ModelCore):
 
     class Meta(MetaCore):
         db_table = 'ethnic_groups'
+        verbose_name = _('population / social group')
 
     def __unicode__(self):
         return self.name
index 640116c8636436c09e81f2a805d14a3c4a98d36f..a3f0e08d08ec455b8c6f9becbd7820b1d65960ec 100644 (file)
@@ -36,6 +36,7 @@
 from django.db.models import Q
 from telemeta.models.core import *
 from telemeta.util.unaccent import unaccent, unaccent_icmp
+from telemeta.models.enum import EthnicGroup
 import re
 
 class MediaItemQuerySet(CoreQuerySet):
@@ -154,9 +155,8 @@ class MediaItemQuerySet(CoreQuerySet):
         return qs                
 
     def ethnic_groups(self):
-        return self.filter(ethnic_group__isnull=False) \
-               .values_list('ethnic_group__name', flat=True) \
-               .distinct().order_by('ethnic_group__name')        
+        ids = self.filter(ethnic_group__isnull=False).values('ethnic_group');
+        return EthnicGroup.objects.filter(pk__in=ids).order_by('name')
 
 class MediaItemManager(CoreManager):
     "Manage media items queries"
@@ -227,7 +227,7 @@ class MediaCollectionQuerySet(CoreQuerySet):
 
     def by_ethnic_group(self, group):
         "Find collections by ethnic group"
-        return self.filter(items__ethnic_group__name=group).distinct()
+        return self.filter(items__ethnic_group=group).distinct()
 
     def by_change_time(self, from_time=None, until_time=None):
         "Find collections between two dates"
index d81df268e33900d4eb2bb44482ade547061f2013..77d9ce12351fc17eca4c00cb102f64947eee0a94 100644 (file)
@@ -34,7 +34,7 @@ $(document).ready(function () {
     </p>
 
     <p>
-    <label for="ethnic_group">Ethnic group</label>
+    <label for="ethnic_group">{% field_label "EthnicGroup" %}</label>
     <select id="ethnic_group" name="ethnic_group">
         <option value="">All ethnic groups</option>
     {% for group in ethnic_groups %}
index faaed22f3d45b6ad9ccf44a33e4b79fc2b7ef4bd..0992678a9ca624558e92309436452ec1adb76631 100644 (file)
@@ -1,5 +1,6 @@
 {% extends "telemeta/base.html" %}
 {% load telemeta_utils %}
+{% load i18n %}
 
 {% block content %}
 <h3>Search results</h3>
@@ -7,13 +8,13 @@
 {% if criteria %}
 <ul>
   {% if criteria.pattern %}
-    <li><b>Pattern:</b> {{criteria.pattern}}</li>
+    <li><b>{% trans "Search pattern" %}:</b> {{criteria.pattern}}</li>
   {% endif %}
   {% if criteria.location %}
-    <li><b>Location:</b> {{criteria.location}}</li>
+    <li><b>{% field_label "Location" %}</b>: {{criteria.location}}</li>
   {% endif %}
   {% if criteria.ethnic_group %}
-    <li><b>Ethnic group:</b> {{criteria.ethnic_group}}</li>
+    <li><b>{% field_label "EthnicGroup" %}:</b> {{criteria.ethnic_group}}</li>
   {% endif %}
   {% if criteria.creator %}
     <li><b>Creator:</b> {{criteria.creator}}</li>
@@ -22,7 +23,7 @@
     <li><b>Title:</b> {{criteria.title}}</li>
   {% endif %}
   {% if criteria.rec_date %}
-    <li><b>Recording date:</b> {{criteria.rec_date}}</li>
+    <li><b>{% trans "Year of recording" %}:</b> {{criteria.rec_date}}</li>
   {% endif %}
   {% if criteria.pub_date %}
     <li><b>Publishing date:</b> {{criteria.pub_date}}</li>
index bd6535573b0c5b809a9e11bfa553a2a0a16fe109..45db6db78afc23b290d19021527d2ec84e9e92dc 100644 (file)
@@ -45,7 +45,7 @@ from django.views.generic import list_detail
 from django.conf import settings
 
 import telemeta
-from telemeta.models import MediaItem, Location, MediaCollection
+from telemeta.models import MediaItem, Location, MediaCollection, EthnicGroup
 from telemeta.models import dublincore
 from telemeta.core import Component, ExtensionPoint
 from telemeta.export import *
@@ -167,9 +167,10 @@ class WebView(Component):
         return response
 
     def edit_search(self, request):
-        ethnic_groups = MediaItem.objects.all().ethnic_groups()
-        return render_to_response('telemeta/search_criteria.html', 
-            {'ethnic_groups': ethnic_groups})
+
+        return render_to_response('telemeta/search_criteria.html', {
+            'ethnic_groups': MediaItem.objects.all().ethnic_groups(),
+        })
 
     def complete_location(self, request, with_items=True):
         input = request.REQUEST
@@ -208,7 +209,8 @@ class WebView(Component):
                 items.filter(continent = value)),
             'ethnic_group': lambda value: (
                 collections.by_ethnic_group(value), 
-                items.filter(ethnie_grsocial = value)),
+                items.filter(ethnic_group = value),
+                EthnicGroup.objects.get(pk=value)),
             'creator': lambda value: (
                 collections.word_search('creator', value),
                 items.word_search('auteur', value)),
@@ -221,11 +223,13 @@ class WebView(Component):
         }
        
         for key, value in input.items():
-            if key == 'continent' and input.get('country'):
-                continue
             func = switch.get(key)
             if func and value:
-                collections, items = func(value)
+                res = func(value)
+                if len(res) > 2:
+                    collections, items, value = res
+                else: 
+                    collections, items = res
                 criteria[key] = value
 
         if type is None: