From 5cda550090b85020cbe4f5041fe1e873fb933068 Mon Sep 17 00:00:00 2001 From: mathieu Date: Mon, 9 May 2016 17:15:03 +0200 Subject: [PATCH] Autocompletion lieu + fix traduction --- env/debug.env | 2 +- telemeta/locale | 2 +- telemeta/models/collection.py | 2 +- telemeta/search_indexes.py | 6 +++--- telemeta/templates/search/advanceSearch.html | 2 +- telemeta/views/search.py | 16 +++++++++++----- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/env/debug.env b/env/debug.env index a19e3477..7a9fbbcc 100644 --- a/env/debug.env +++ b/env/debug.env @@ -18,4 +18,4 @@ BROKER_URL=redis://broker:6379/0 # If this is True, all tasks will be executed locally by blocking until the task returns. CELERY_ALWAYS_EAGER=False -REINDEX=False +REINDEX=True diff --git a/telemeta/locale b/telemeta/locale index 308a1e8c..66caac4d 160000 --- a/telemeta/locale +++ b/telemeta/locale @@ -1 +1 @@ -Subproject commit 308a1e8cfbeb2768f3e24660971d774e303e63b3 +Subproject commit 66caac4dce0b50451e5755e42240444ad33e9647 diff --git a/telemeta/models/collection.py b/telemeta/models/collection.py index af421ebf..419d765c 100644 --- a/telemeta/models/collection.py +++ b/telemeta/models/collection.py @@ -198,7 +198,7 @@ class MediaCollection(MediaResource): elif '_E_' in self.public_id: return 'Published' else: - return '' + return 'Unknown' def get_url(self): return get_full_url(reverse('telemeta-collection-detail', kwargs={'public_id':self.pk})) diff --git a/telemeta/search_indexes.py b/telemeta/search_indexes.py index fc7475ae..53769300 100644 --- a/telemeta/search_indexes.py +++ b/telemeta/search_indexes.py @@ -75,7 +75,7 @@ class MediaItemIndex(indexes.SearchIndex, indexes.Indexable): #print u"".join(' ' + local for local in location).encode("utf-8") #print u"%s".encode("utf-8") % location #print [local for local in location] - return u"".join(' ' + local for local in location) + return u"".join('|' + local for local in location) def prepare_instruments(self, obj): item = MediaItemPerformance.objects.all().filter(media_item__exact=obj) @@ -129,7 +129,7 @@ class MediaCollectionIndex(indexes.SearchIndex, indexes.Indexable): location = [] if item.location is not None: collec_location.append(item.location.name) - return u"".join(' ' + location for location in collec_location) + return u"".join('|' + location for location in collec_location) def prepare_location_relation(self, obj): collec_location = [] @@ -145,7 +145,7 @@ class MediaCollectionIndex(indexes.SearchIndex, indexes.Indexable): for name in location: if name and not name in collec_location: collec_location.append(name) - return u"".join(' ' + location for location in collec_location) + return u"".join('|' + location for location in collec_location) def prepare_ethnic_group(self, obj): return "%s" % obj.ethnic_groups() diff --git a/telemeta/templates/search/advanceSearch.html b/telemeta/templates/search/advanceSearch.html index 14e33079..146536a3 100644 --- a/telemeta/templates/search/advanceSearch.html +++ b/telemeta/templates/search/advanceSearch.html @@ -324,7 +324,7 @@ $(function() { } - activerAutocompletion($('#id_code, #id_instruments, #id_collectors')); + activerAutocompletion($('#id_code, #id_instruments, #id_collectors, #id_location')); var colTri = []; diff --git a/telemeta/views/search.py b/telemeta/views/search.py index 4b6f18fd..d6ee584f 100644 --- a/telemeta/views/search.py +++ b/telemeta/views/search.py @@ -167,14 +167,20 @@ class HaystackAdvanceSearch(SavedSearchView): def autocomplete(request): sqs = SearchQuerySet().load_all() - if request.GET.get('attr', '') == "instruments": - sqs = sqs.filter(instruments__startswith=request.GET.get('q', '')) - instrus = [result.instruments for result in sqs] + if request.GET.get('attr', '') == "instruments" or request.GET.get('attr', '') == "location": + if request.GET.get('attr', '') == "instruments": + sqs = sqs.filter(instruments__startswith=request.GET.get('q', '')) + objets = [result.instruments for result in sqs] + #instrus = [result.instruments for result in sqs] + elif request.GET.get('attr', '') == "location": + sqs = sqs.filter(location_principal__startswith=request.GET.get('q', '')).filter_or(location_relation__startswith=request.GET.get('q', '')) + objets = [result.location_principal for result in sqs] suggestions = [] - for chaine in instrus: + for chaine in objets : + #for chaine in instrus: for word in chaine.split('|'): if word != "" and escapeAccentAndLower(request.GET.get('q', '')) in escapeAccentAndLower(word): - suggestions.append(word) + suggestions.append(word) elif request.GET.get('attr', '') == "code": sqs = sqs.filter(code__contains=request.GET.get('q', '')) suggestions = [result.code for result in sqs] -- 2.39.5