예제 #1
0
파일: MPQuery.py 프로젝트: leo831/stoqs
    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', )
예제 #2
0
    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',)