def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0): ''' Query records from underlying repository ''' # run the raw query and get total if 'where' in constraint: # GetRecords with constraint query = Resource.objects.extra(where=[constraint['where']], params=constraint['values']) else: # GetRecords sans constraint query = Resource.objects total = query.count() # apply sorting, limit and offset if sortby is not None: if 'spatial' in sortby and sortby['spatial']: # spatial sort desc = False if sortby['order'] == 'DESC': desc = True query = query.all() return [str(total), sorted(query, key=lambda x: float(util.get_geometry_area(getattr(x, sortby['propertyname']))), reverse=desc)[startposition:maxrecords]] if sortby['order'] == 'DESC': pname = '-%s' % sortby['propertyname'] else: pname = sortby['propertyname'] return [str(total), \ query.order_by(pname)[startposition:maxrecords]] else: # no sort return [str(total), query.all()[startposition:maxrecords]]
def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0): ''' Query records from underlying repository ''' # run the raw query and get total if 'where' in constraint: # GetRecords with constraint query = self._get_repo_filter(Resource.objects).extra(where=[constraint['where']], params=constraint['values']) else: # GetRecords sans constraint query = self._get_repo_filter(Resource.objects) total = query.count() # apply sorting, limit and offset if sortby is not None: if 'spatial' in sortby and sortby['spatial']: # spatial sort desc = False if sortby['order'] == 'DESC': desc = True query = query.all() return [str(total), sorted(query, key=lambda x: float(util.get_geometry_area(getattr(x, sortby['propertyname']))), reverse=desc)[startposition:startposition+int(maxrecords)]] if sortby['order'] == 'DESC': pname = '-%s' % sortby['propertyname'] else: pname = sortby['propertyname'] return [str(total), \ query.order_by(pname)[startposition:startposition+int(maxrecords)]] else: # no sort return [str(total), query.all()[startposition:startposition+int(maxrecords)]]
def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0): """ Query records from underlying repository """ # run the raw query and get total if "where" in constraint: # GetRecords with constraint query = Resource.objects.extra(where=[constraint["where"]], params=constraint["values"]) else: # GetRecords sans constraint query = Resource.objects total = query.count() # apply sorting, limit and offset if sortby is not None: if "spatial" in sortby and sortby["spatial"]: # spatial sort desc = False if sortby["order"] == "DESC": desc = True query = query.all() return [ str(total), sorted( query, key=lambda x: float(util.get_geometry_area(getattr(x, sortby["propertyname"]))), reverse=desc, )[startposition:maxrecords], ] if sortby["order"] == "DESC": pname = "-%s" % sortby["propertyname"] else: pname = sortby["propertyname"] return [str(total), query.order_by(pname)[startposition:maxrecords]] else: # no sort return [str(total), query.all()[startposition:maxrecords]]
def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0): ''' Query records from underlying repository ''' # run the raw query and get total if 'where' in constraint: # GetRecords with constraint # escape wildcards for django if constraint['where'].find('%') != -1: constraint['where'] = constraint['where'].replace('%','%%') query = Resource.objects.extra(where=[constraint['where']]) else: # GetRecords sans constraint query = Resource.objects total = query.count() # apply sorting, limit and offset if sortby is not None: if 'spatial' in sortby and sortby['spatial']: # spatial sort desc = False if sortby['order'] == 'DESC': desc = True return [str(total), sorted(query, key=lambda x: float(util.get_geometry_area(getattr(x, sortby['propertyname']))), reverse=desc)[startposition:maxrecords]] if sortby['order'] == 'DESC': pname = '-%s' % sortby['propertyname'] else: pname = sortby['propertyname'] return [str(total), \ query.order_by(pname)[startposition:maxrecords]] else: # no sort return [str(total), query[startposition:maxrecords]]
def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0): ''' Query records from underlying repository ''' # run the raw query and get total if constraint.has_key('where'): # GetRecords with constraint # escape wildcards for django if constraint['where'].find('%') != -1: constraint['where'] = constraint['where'].replace('%', '%%') if not typenames: # any typename query = Resource.objects.extra(where=[constraint['where']]) else: query = Resource.objects.filter( csw_typename__in=typenames).extra( where=[constraint['where']]) total = query.count() else: # GetRecords sans constraint if not typenames: # any typename query = Resource.objects else: query = Resource.objects.filter(csw_typename__in=typenames) total = query.count() # apply sorting, limit and offset if sortby is not None: if sortby.has_key( 'spatial') and sortby['spatial'] is True: # spatial sort desc = False if sortby['order'] == 'DESC': desc = True return [ str(total), sorted(query, key=lambda x: float( util.get_geometry_area( getattr(x, sortby['propertyname']))), reverse=desc)[startposition:maxrecords] ] if sortby['order'] == 'DESC': pname = '-%s' % sortby['propertyname'] else: pname = sortby['propertyname'] return [str(total), \ query.order_by(pname)[startposition:maxrecords]] else: # no sort return [str(total), query[startposition:maxrecords]]