2010-11-26 15:07:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
from django.db.models import Q, Manager
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-11-26 15:07:24 +00:00
|
|
|
|
|
|
|
class PlaceManager(Manager):
|
2011-01-01 11:44:42 +00:00
|
|
|
|
2010-11-26 15:07:24 +00:00
|
|
|
def get_query_set(self):
|
|
|
|
return super(PlaceManager, self).get_query_set()
|
|
|
|
|
2011-02-24 18:39:58 +00:00
|
|
|
def find(self, q='', south=-180.0, west=-180.0, north=180.0, east=180.0):
|
2010-11-26 15:07:24 +00:00
|
|
|
qs = self.get_query_set()
|
|
|
|
qs = qs.filter(Q(
|
2011-02-24 18:39:58 +00:00
|
|
|
Q(Q(south__gt=south)|Q(south__lt=north)|Q(west__gt=west)|Q(west__lt=east)) &
|
|
|
|
Q(Q(south__gt=south)|Q(south__lt=north)|Q(west__lt=east)|Q(east__gt=east)) &
|
|
|
|
Q(Q(north__gt=south)|Q(north__lt=north)|Q(west__gt=west)|Q(west__lt=east)) &
|
|
|
|
Q(Q(north__gt=south)|Q(north__lt=north)|Q(east__gt=west)|Q(east__lt=east))
|
2010-11-26 15:07:24 +00:00
|
|
|
))
|
|
|
|
if q:
|
2011-01-01 11:44:42 +00:00
|
|
|
qs = qs.filter(name_find__icontains=q)
|
2010-11-26 15:07:24 +00:00
|
|
|
return qs
|
|
|
|
'''
|
|
|
|
#only return locations that have layers of videos visible to current user
|
|
|
|
if not identity.current.anonymous:
|
|
|
|
user = identity.current.user
|
|
|
|
if not user.in_group('admin'):
|
|
|
|
query = AND(query,
|
|
|
|
id == Layer.q.locationID, Layer.q.videoID == Video.q.id,
|
|
|
|
OR(Video.q.public == True, Video.q.creatorID == user.id)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
query = AND(query,
|
|
|
|
id == Layer.q.locationID, Layer.q.videoID == Video.q.id,
|
|
|
|
Video.q.public == True)
|
|
|
|
'''
|