Beispiel #1
0
def call_resource(path, qs, per_page=5000):
    app = task_utils.get_app()
    endpoint, arguments = app.url_map.bind('').match(path)
    resource_type = app.view_functions[endpoint].view_class
    if resource_type not in RESOURCE_WHITELIST:
        raise ValueError('Downloads on resource {} not supported'.format(resource_type.__name__))
    resource = resource_type()
    fields, kwargs = parse_kwargs(resource, qs)
    kwargs = utils.extend(arguments, kwargs)
    for field in IGNORE_FIELDS:
        kwargs.pop(field, None)
    query, model, schema = unpack(resource.build_query(**kwargs), 3)
    count = counts.count_estimate(query, db.session, threshold=5000)
    index_column = utils.get_index_column(model or resource.model)
    query_kwargs = utils.extend(kwargs, {'per_page': per_page})
    paginator = utils.fetch_seek_paginator(query, query_kwargs, index_column, count=count, cap=None)
    return {
        'path': path,
        'qs': qs,
        'name': get_s3_name(path, qs),
        'paginator': paginator,
        'schema': schema or resource.schema,
        'resource': resource,
        'count': count,
        'timestamp': datetime.datetime.utcnow(),
        'fields': fields,
        'kwargs': kwargs,
    }
Beispiel #2
0
def call_resource(path, qs):
    app = task_utils.get_app()
    endpoint, arguments = app.url_map.bind('').match(path)
    resource_type = app.view_functions[endpoint].view_class
    resource = resource_type()
    fields, kwargs = parse_kwargs(resource, qs)
    kwargs = utils.extend(arguments, kwargs)

    for field in IGNORE_FIELDS:
        kwargs.pop(field, None)

    query, model, schema = unpack(resource.build_query(**kwargs), 3)
    count = counts.count_estimate(query, db.session)
    return {
        'path': path,
        'qs': qs,
        'name': get_s3_name(path, qs),
        'query': query,
        'schema': schema or resource.schema,
        'resource': resource,
        'count': count,
        'timestamp': datetime.datetime.utcnow(),
        'fields': fields,
        'kwargs': kwargs,
    }
Beispiel #3
0
 def get(self, **kwargs):
     query = self.build_query(**kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query,
                             kwargs,
                             model=models.Filings,
                             count=count)
Beispiel #4
0
def call_resource(path, qs):
    app = task_utils.get_app()
    endpoint, arguments = app.url_map.bind('').match(path)
    resource_type = app.view_functions[endpoint].view_class
    if resource_type not in RESOURCE_WHITELIST:
        raise ValueError('Downloads on resource {} not supported'.format(
            resource_type.__name__))
    resource = resource_type()
    fields, kwargs = parse_kwargs(resource, qs)
    kwargs = utils.extend(arguments, kwargs)
    for field in IGNORE_FIELDS:
        kwargs.pop(field, None)
    query, model, schema = unpack(resource.build_query(**kwargs), 3)
    count = counts.count_estimate(query, db.session, threshold=5000)
    return {
        'path': path,
        'qs': qs,
        'name': get_s3_name(path, qs),
        'query': query,
        'schema': schema or resource.schema,
        'resource': resource,
        'count': count,
        'timestamp': datetime.datetime.utcnow(),
        'fields': fields,
        'kwargs': kwargs,
    }
Beispiel #5
0
 def get(self, **kwargs):
     query = self.build_query(kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_seek_page(query,
                                  kwargs,
                                  self.index_column,
                                  count=count)
Beispiel #6
0
 def get(self, **kwargs):
     if kwargs.get('form_type') and 'RFAI' in kwargs.get('form_type'):
         #Adds FRQ types if RFAI was requested
         kwargs.get('form_type').append('FRQ')
     query = self.build_query(**kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=models.Filings, count=count, multi=True)
Beispiel #7
0
 def build_committee_query(self, kwargs, committee_id):
     query = self.build_query(utils.extend(kwargs, {'committee_id': [committee_id]}), join=False)
     sort, hide_null, nulls_large = kwargs['sort'], kwargs['sort_hide_null'], kwargs['sort_nulls_large']
     query, _ = sorting.sort(query, sort, model=models.ScheduleA, hide_null=hide_null, nulls_large=nulls_large)
     page_query = utils.fetch_seek_page(query, kwargs, self.index_column, count=-1, eager=False).results
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return page_query, count
Beispiel #8
0
 def get(self, **kwargs):
     """Get itemized resources. If multiple values are passed for `committee_id`,
     create a subquery for each and combine with `UNION ALL`. This is necessary
     to avoid slow queries when one or more relevant committees has many
     records.
     """
     committee_ids = kwargs.get('committee_id', [])
     if len(committee_ids) > 5:
         raise exceptions.ApiError(
             'Can only specify up to five values for "committee_id".',
             status_code=422,
         )
     if len(committee_ids) > 1:
         query, count = self.join_committee_queries(kwargs)
         return utils.fetch_seek_page(query,
                                      kwargs,
                                      self.index_column,
                                      count=count)
     query = self.build_query(**kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_seek_page(query,
                                  kwargs,
                                  self.index_column,
                                  count=count,
                                  cap=self.cap)
Beispiel #9
0
 def get(self, *args, **kwargs):
     query = self.build_query(*args, **kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(
         query, kwargs,
         count=count, model=self.model, join_columns=self.join_columns, aliases=self.aliases,
         index_column=self.index_column, cap=self.cap,
     )
Beispiel #10
0
 def get(self, committee_id=None, **kwargs):
     query = self.build_query(committee_id=committee_id, **kwargs)
     count = counts.count_estimate(query, models.db.session)
     return utils.fetch_page(query,
                             kwargs,
                             model=self.model,
                             count=count,
                             index_column=self.index_column)
Beispiel #11
0
    def get(self, committee_type=None, **kwargs):
        if committee_type:
            self.model, self.schema, self.page_schema = \
                efile_reports_schema_map.get(form_type_map.get(committee_type))
        query = self.build_query(**kwargs)

        count = counts.count_estimate(query, models.db.session, threshold=5000)
        return utils.fetch_page(query, kwargs, model=self.model, count=count)
Beispiel #12
0
 def build_committee_query(self, kwargs, committee_id):
     """Build a subquery by committee.
     """
     query = self.build_query(_apply_options=False, **utils.extend(kwargs, {'committee_id': [committee_id]}))
     sort, hide_null = kwargs['sort'], kwargs['sort_hide_null']
     query, _ = sorting.sort(query, sort, model=self.model, hide_null=hide_null)
     page_query = utils.fetch_seek_page(query, kwargs, self.index_column, count=-1, eager=False).results
     count = counts.count_estimate(query, models.db.session)
     return page_query, count
Beispiel #13
0
 def build_committee_query(self, kwargs, committee_id):
     """Build a subquery by committee.
     """
     query = self.build_query(_apply_options=False, **utils.extend(kwargs, {'committee_id': [committee_id]}))
     sort, hide_null, nulls_large = kwargs['sort'], kwargs['sort_hide_null'], kwargs['sort_nulls_large']
     query, _ = sorting.sort(query, sort, model=self.model, hide_null=hide_null, nulls_large=nulls_large)
     page_query = utils.fetch_seek_page(query, kwargs, self.index_column, count=-1, eager=False).results
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return page_query, count
Beispiel #14
0
    def get(self, *args, **kwargs):
        query = self.build_query(*args, **kwargs)
        count = counts.count_estimate(query, models.db.session)
        multi = False
        if isinstance(kwargs['sort'], (list, tuple)):
            multi = True

        return utils.fetch_page(
            query, kwargs,
            count=count, model=self.model, join_columns=self.join_columns, aliases=self.aliases,
            index_column=self.index_column, cap=self.cap, multi=multi,
        )
Beispiel #15
0
    def get(self, committee_type=None, **kwargs):
        if committee_type:
            self.model, self.schema, self.page_schema = \
                efile_reports_schema_map.get(form_type_map.get(committee_type))
            #Filters need to be set dynamically at runtime (otherwise sql alchemy couldn't
            #determine proper table repid for the join operation)
            self.filter_multi_fields[0] = ('file_number',
                                           self.model.file_number)
        query = self.build_query(**kwargs)

        count = counts.count_estimate(query, models.db.session, threshold=5000)
        return utils.fetch_page(query, kwargs, model=self.model, count=count)
Beispiel #16
0
 def get(self, *args, **kwargs):
     query = self.build_query(*args, **kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(
         query,
         kwargs,
         count=count,
         model=self.model,
         join_columns=self.join_columns,
         aliases=self.aliases,
         index_column=self.index_column,
         cap=self.cap,
     )
Beispiel #17
0
 def get(self, **kwargs):
     """Get itemized resources. If multiple values are passed for `committee_id`,
     create a subquery for each and combine with `UNION ALL`. This is necessary
     to avoid slow queries when one or more relevant committees has many
     records.
     """
     committee_ids = kwargs.get('committee_id', [])
     if len(committee_ids) > 5:
         raise exceptions.ApiError(
             'Can only specify up to five values for "committee_id".',
             status_code=422,
         )
     if len(committee_ids) > 1:
         query, count = self.join_committee_queries(kwargs)
         return utils.fetch_seek_page(query, kwargs, self.index_column, count=count)
     query = self.build_query(**kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_seek_page(query, kwargs, self.index_column, count=count)
Beispiel #18
0
 def build_committee_query(self, kwargs, committee_id):
     query = self.build_query(utils.extend(
         kwargs, {'committee_id': [committee_id]}),
                              join=False)
     sort, hide_null, nulls_large = kwargs['sort'], kwargs[
         'sort_hide_null'], kwargs['sort_nulls_large']
     query, _ = sorting.sort(query,
                             sort,
                             model=models.ScheduleA,
                             hide_null=hide_null,
                             nulls_large=nulls_large)
     page_query = utils.fetch_seek_page(query,
                                        kwargs,
                                        self.index_column,
                                        count=-1,
                                        eager=False).results
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return page_query, count
Beispiel #19
0
 def get(self, committee_id=None, **kwargs):
     query = models.Filings.query
     query = query.filter_by(committee_id=committee_id)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=models.Filings, count=count)
Beispiel #20
0
 def get(self, committee_id=None, **kwargs):
     query = self._build_query(committee_id, kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=self.model, count=count)
Beispiel #21
0
 def get(self, **kwargs):
     query = self.build_query(**kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_seek_page(query, kwargs, self.index_column, count=count)
Beispiel #22
0
 def get(self, **kwargs):
     query = models.Filings.query
     query = filter_query(models.Filings, query, fields, kwargs)
     query = utils.filter_range(query, kwargs, range_fields)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=models.Filings, count=count)
Beispiel #23
0
 def get(self, committee_id=None, **kwargs):
     query = self.build_query(committee_id=committee_id, **kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=self.model, count=count, index_column=self.index_column)
Beispiel #24
0
 def get(self, **kwargs):
     query = self.build_query(**kwargs)
     count = counts.count_estimate(query, models.db.session, threshold=5000)
     return utils.fetch_page(query, kwargs, model=models.Filings, count=count)