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, }
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, }
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, }
def parse_kwargs(resource, qs): annotation = resolve_annotations(resource.get, 'args', parent=resource) fields = utils.extend(*[option['args'] for option in annotation.options]) with task_utils.get_app().test_request_context(b'?' + qs): kwargs = flaskparser.parser.parse(fields) return fields, kwargs
def push_context(task_id, task, *args, **kwargs): context[task_id] = utils.get_app().app_context() context[task_id].push()