def __init__(self, dbAlias, query, values_list, qs_mp=None): ''' Initialize MPQuerySet with either raw SQL in @query or a QuerySet in @qs_mp. Use @values_list to request just the fields (columns) needed. The class variables rest_colums and kml_columns are typical value_lists. Note: specifying a values_list appears to break the correct serialization of geometry types in the json response. Called by stoqs/views/__init__.py when MeasuredParameter REST requests are made. ''' self.isRawQuerySet = False if query is None and qs_mp is not None: logger.debug('query is None and qs_mp is not None') self.query = postgresifySQL(str(qs_mp.query)) self.mp_query = qs_mp elif query is not None and qs_mp is None: logger.debug('query is not None and qs_mp is None') self.query = query query = PQuery.addPrimaryKey(query) self.mp_query = MeasuredParameter.objects.using(dbAlias).raw(query) self.isRawQuerySet = True else: raise Exception( 'Either query or qs_mp must be not None and the other be None.' ) self.dbAlias = dbAlias self.values_list = values_list self.ordering = ('id', )
def __init__(self, dbAlias, query, values_list, qs_mp=None): ''' Initialize MPQuerySet with either raw SQL in @query or a QuerySet in @qs_mp. Use @values_list to request just the fields (columns) needed. The class variables rest_colums and kml_columns are typical value_lists. Note: specifying a values_list appears to break the correct serialization of geometry types in the json response. Called by stoqs/views/__init__.py when MeasuredParameter REST requests are made. ''' self.isRawQuerySet = False if query is None and qs_mp is not None: logger.debug('query is None and qs_mp is not None') self.query = postgresifySQL(str(qs_mp.query)) self.mp_query = qs_mp elif query is not None and qs_mp is None: logger.debug('query is not None and qs_mp is None') self.query = query query = PQuery.addPrimaryKey(query) self.mp_query = MeasuredParameter.objects.using(dbAlias).raw(query) self.isRawQuerySet = True else: raise Exception('Either query or qs_mp must be not None and the other be None.') self.dbAlias = dbAlias self.values_list = values_list self.ordering = ('id',)