Show
Ignore:
Timestamp:
02/17/10 16:20:36 (7 months ago)
Author:
olivier
Message:

searching by a location now takes into account location historicity ; do not list historical countries in the geo navigator anymore ; improve geocoder, geocoding only current locations (not historical) and searchin by location alias as a fallback

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/telemeta/models/query.py

    r580 r582  
    8484    def by_location(self, location): 
    8585        "Find items by location" 
    86         return self.filter(Q(location=location) | Q(location__in=location.descendants())) 
     86        return self.filter(location__in=location.apparented()) 
    8787            
    8888    @staticmethod 
     
    9393        from telemeta.models import Location, LocationRelation 
    9494        l = self.values('location') 
     95        c = self.values('location__current_location') 
    9596        r = LocationRelation.objects.filter(location__in=l).values('ancestor_location') 
    96         return Location.objects.filter(Q(pk__in=l) | Q(pk__in=r)) 
     97        return Location.objects.filter(Q(pk__in=l) | Q(pk__in=r) | Q(pk__in=c)) 
    9798 
    9899    def countries(self, group_by_continent=False): 
     
    102103            location = Location.objects.get(pk=id) 
    103104            for l in location.countries(): 
    104                 if not l in countries: 
    105                     countries.append(l) 
     105                c = l.current_location 
     106                if not c in countries: 
     107                    countries.append(c) 
    106108 
    107109        if group_by_continent: 
     
    226228    def by_location(self, location): 
    227229        "Find collections by location" 
    228         return self.filter(Q(items__location=location) | Q(items__location__in=location.descendants())).distinct() 
     230        return self.filter(items__location__in=location.apparented()).distinct() 
    229231     
    230232    def by_recording_year(self, from_year, to_year=None): 
     
    352354        return map 
    353355 
    354     def current(self, is_current=True): 
    355         if is_current: 
    356             where = ["locations.id = locations.current_location_id"] 
    357         else: 
    358             where = ["locations.id <> locations.current_location_id"] 
    359  
    360         return self.extra(where = where); 
     356    def current(self): 
     357        return self.filter(id__in=self.values_list('current_location_id', flat=True)).distinct() 
    361358 
    362359class LocationManager(CoreManager):