Changeset c1a2c1c
- Timestamp:
- 02/10/10 19:25:21 (3 years ago)
- Branches:
- master, crem, crem2, dev, diadems, forma, generic, instru_search, lam, nlivemulti, production, release/1.4.4, security, social, storage, test, video
- Children:
- 12d665f
- Parents:
- 622588f
- git-author:
- olivier <> (02/10/10 19:25:21)
- git-committer:
- olivier <> (02/10/10 19:25:21)
- Location:
- telemeta
- Files:
-
- 2 added
- 2 deleted
- 5 edited
-
htdocs/css/jquery.autocomplete.css (added)
-
htdocs/js/jquery.autocomplete.js (added)
-
models/query.py (modified) (1 diff)
-
templates/telemeta/geo_continents.js (deleted)
-
templates/telemeta_default/geo_continents.js (deleted)
-
templates/telemeta_default/search_criteria.html (modified) (3 diffs)
-
templates/telemeta_default/search_results.html (modified) (1 diff)
-
urls.py (modified) (2 diffs)
-
web/base.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telemeta/models/query.py
r622588f rc1a2c1c 80 80 def by_location(self, location): 81 81 "Find items by location" 82 from telemeta.models import LocationRelation 83 descendants = LocationRelation.objects.filter(ancestor_location=location) 84 return self.filter(Q(location=location) | Q(location__in=descendants)) 82 return self.filter(Q(location=location) | Q(location__in=location.descendants())) 85 83 86 84 @staticmethod 87 85 def __name_cmp(obj1, obj2): 88 86 return unaccent_icmp(obj1.name, obj2.name) 87 88 def locations(self): 89 from telemeta.models import Location, LocationRelation 90 l = self.values('location') 91 r = LocationRelation.objects.filter(location__in=l).values('ancestor_location') 92 return Location.objects.filter(Q(pk__in=l) | Q(pk__in=r)) 89 93 90 94 def countries(self, group_by_continent=False): -
telemeta/templates/telemeta_default/search_criteria.html
r9d3f1f3 rc1a2c1c 1 1 {% extends "telemeta/base.html" %} 2 2 {% load telemeta_utils %} 3 {% load i18n %} 4 5 {% block stylesheets %} 6 {{ block.super }} 7 <link rel="stylesheet" type="text/css" href="{% url telemeta-css "jquery.autocomplete.css" %}" /> 8 {% endblock %} 3 9 4 10 {% block extra_javascript %} 5 <script src="{% url telemeta-continents-js %}" type="text/javascript"></script> 11 <script src="{% url telemeta-js "jquery.autocomplete.js" %}" type="text/javascript"></script> 12 <script type="text/javascript"> 13 $(document).ready(function () { 14 $('#location').autocomplete('{% url telemeta-complete-location %}', { 15 max: 20, 16 formatResult: function(data) { 17 console.log(data); 18 return data[0].replace(/ *\([0-9]+.*\) *$/, ''); 19 } 20 }); 21 }); 22 </script> 6 23 {% endblock %} 7 24 … … 13 30 14 31 <p> 15 <label for="continent">Continent</label> 16 <select id="continent" name="continent" onchange="update_countries(this, document.getElementById('country'));"> 17 <option value="">All continents</option> 18 {% for continent in continents %} 19 <option value="{{continent|escape}}">{{continent|escape}}</option> 20 {% endfor %} 21 </select> 22 </p> 23 24 <p> 25 <label for="country">Country</label> 26 <select name="country" id="country"> 27 <option value="">All countries</option> 28 {% for country in countries %} 29 <option value="{{country.1|escape}}">{{country.1|escape}}</option> 30 {% endfor %} 31 </select> 32 <label for="location">{% trans "Location" %}</label> 33 <input type="text" name="location" id="location" /> 32 34 </p> 33 35 … … 37 39 <option value="">All ethnic groups</option> 38 40 {% for group in ethnic_groups %} 39 <option value="{{group |escape}}">{{group|escape}}</option>41 <option value="{{group.id}}">{{group|escape}}</option> 40 42 {% endfor %} 41 43 </select> -
telemeta/templates/telemeta_default/search_results.html
r9d3f1f3 rc1a2c1c 10 10 <li><b>Pattern:</b> {{criteria.pattern}}</li> 11 11 {% endif %} 12 {% if criteria.continent %} 13 <li><b>Continent:</b> {{criteria.continent}}</li> 14 {% endif %} 15 {% if criteria.country %} 16 <li><b>Country:</b> {{criteria.country}}</li> 12 {% if criteria.location %} 13 <li><b>Location:</b> {{criteria.location}}</li> 17 14 {% endif %} 18 15 {% if criteria.ethnic_group %} -
telemeta/urls.py
r619d1a8 rc1a2c1c 112 112 name="telemeta-search-items"), 113 113 url(r'^search/criteria/$', web_view.edit_search, name="telemeta-search-criteria"), 114 url(r'^complete_location/$', web_view.complete_location, name="telemeta-complete-location"), 114 115 115 116 # administration … … 145 146 web_view.list_country_items, 146 147 name="telemeta-geo-country-items"), 147 url(r'^dynjs/continents.js$', web_view.get_continents_js, name="telemeta-continents-js"),148 148 url(r'^geo/country_info/(?P<id>[0-9A-Z]+)/$', 149 149 web_view.country_info, name="telemeta-country-info"), -
telemeta/web/base.py
r619d1a8 rc1a2c1c 162 162 163 163 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() 167 165 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)) 170 182 171 183 def search(self, request, type = None): 172 184 """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() 175 187 input = request.REQUEST 176 188 criteria = {} … … 183 195 collections.word_search('title', value), 184 196 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))), 188 200 'continent': lambda value: ( 189 201 collections.by_continent(value), … … 347 359 'country': country, 'continent': country.continents()[0]}) 348 360 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 354 361 def list_countries(self, request, continent): 355 362 continent = Location.objects.by_flatname(continent)[0]
Note: See TracChangeset
for help on using the changeset viewer.
