class Meta(MetaCore):
db_table = 'ethnic_groups'
+ verbose_name = _('population / social group')
def __unicode__(self):
return self.name
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):
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"
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"
</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 %}
{% extends "telemeta/base.html" %}
{% load telemeta_utils %}
+{% load i18n %}
{% block content %}
<h3>Search results</h3>
{% 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>
<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>
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 *
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
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)),
}
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: