コード例 #1
0
ファイル: csv_builder.py プロジェクト: babacar/onadata
    def _query_data(self,
                    query='{}',
                    start=0,
                    limit=ParsedInstance.DEFAULT_LIMIT,
                    fields='[]',
                    count=False):
        # query_data takes params as json strings
        # so we dumps the fields dictionary
        count_args = {
            'xform': self.xform,
            'query': query,
            'start': self.start,
            'end': self.end,
            'fields': '[]',
            'sort': '{}',
            'count': True
        }
        count_object = list(query_data(**count_args))
        record_count = count_object[0]["count"]
        if record_count < 1:
            raise NoRecordsFoundError("No records found for your query")
        # if count was requested, return the count
        if count:
            return record_count
        else:
            query_args = {
                'xform': self.xform,
                'query': query,
                'fields': fields,
                'start': self.start,
                'end': self.end,
                # TODO: we might want to add this in for the user
                # to sepcify a sort order
                'sort': 'id',
                'start_index': start,
                'limit': limit,
                'count': False
            }
            cursor = query_data(**query_args)

            return cursor
コード例 #2
0
 def _query_mongo(self,
                  query='{}',
                  start=0,
                  limit=ParsedInstance.DEFAULT_LIMIT,
                  fields='[]',
                  count=False):
     # ParsedInstance.query_mongo takes params as json strings
     # so we dumps the fields dictionary
     count_args = {
         'username': self.username,
         'id_string': self.id_string,
         'query': query,
         'fields': '[]',
         'sort': '{}',
         'count': True
     }
     count_object = ParsedInstance.query_mongo(**count_args)
     record_count = count_object[0]["count"]
     if record_count == 0:
         raise NoRecordsFoundError("No records found for your query")
     # if count was requested, return the count
     if count:
         return record_count
     else:
         query_args = {
             'username': self.username,
             'id_string': self.id_string,
             'query': query,
             'fields': fields,
             # TODO: we might want to add this in for the user
             # to sepcify a sort order
             'sort': '{}',
             'start': start,
             'limit': limit,
             'count': False
         }
         # use ParsedInstance.query_mongo
         cursor = ParsedInstance.query_mongo(**query_args)
         return cursor