Ignore:
Timestamp:
02/10/10 19:25:21 (4 years ago)
Author:
olivier <>
Branches:
master, crem, crem2, dev, dev2, diadems, feature/breadcrumbs, feature/ts-0.5, feature/ts-0.5.4, feature/writecache, forma, generic, instru_search, lam, lam2, mapsv3, merge, nlivemulti, production, release/1.4.4, sabiod, security, server, social, storage, telecaster, test, video
Children:
12d665f
Parents:
622588f
git-author:
olivier <> (02/10/10 19:25:21)
git-committer:
olivier <> (02/10/10 19:25:21)
Message:

add autocompleted location input field to advanced search

File:
1 edited

Legend:

Unmodified
Added
Removed
  • telemeta/web/base.py

    r619d1a8 rc1a2c1c  
    162162 
    163163    def edit_search(self, request): 
    164         continents = MediaCollection.objects.list_continents() 
    165         countries = MediaCollection.objects.list_countries() 
    166         ethnic_groups = MediaItem.objects.list_ethnic_groups() 
     164        ethnic_groups = MediaItem.objects.all().ethnic_groups() 
    167165        return render_to_response('telemeta/search_criteria.html',  
    168             {'continents': continents, 'countries': countries,  
    169             'ethnic_groups': ethnic_groups}) 
     166            {'ethnic_groups': ethnic_groups}) 
     167 
     168    def complete_location(self, request, with_items=True): 
     169        input = request.REQUEST 
     170        
     171        token = input['q'] 
     172        limit = int(input['limit']) 
     173        if with_items: 
     174            locations = MediaItem.objects.all().locations() 
     175        else: 
     176            locations = Location.objects.all() 
     177 
     178        locations = locations.filter(name__istartswith=token).order_by('name')[:limit] 
     179        data = [unicode(l) + " (%d items)" % l.items().count() for l in locations] 
     180 
     181        return HttpResponse("\n".join(data)) 
    170182 
    171183    def search(self, request, type = None): 
    172184        """Perform a search through collections and items metadata""" 
    173         collections = MediaCollection.objects.all() 
    174         items = MediaItem.objects.all() 
     185        collections = MediaCollection.objects.enriched() 
     186        items = MediaItem.objects.enriched() 
    175187        input = request.REQUEST 
    176188        criteria = {} 
     
    183195                collections.word_search('title', value),  
    184196                items.by_title(value)), 
    185             'country': lambda value: ( 
    186                 collections.by_country(value),  
    187                 items.filter(etat = value)), 
     197            'location': lambda value: ( 
     198                collections.by_location(Location.objects.get(name=value)),  
     199                items.by_location(Location.objects.get(name=value))), 
    188200            'continent': lambda value: ( 
    189201                collections.by_continent(value),  
     
    347359            'country': country, 'continent': country.continents()[0]}) 
    348360 
    349     def get_continents_js(self, request): 
    350         countries = MediaCollection.objects.list_countries() 
    351         return render_to_response('telemeta/geo_continents.js',  
    352                     {'countries': countries}) 
    353  
    354361    def list_countries(self, request, continent):                     
    355362        continent = Location.objects.by_flatname(continent)[0] 
Note: See TracChangeset for help on using the changeset viewer.