def list_resources(app): """ Iterator; list of all resources :param app: :return: """ # Dictionary of all resources to be added resources = { # FIXME: Update <str:id> to ensure mongo GUID '/{slug}/<string:identifier>/': RecordAPIResource, '/{slug}/': ListAPIResource, '/{slug}/transcription': CustomAPIResource, '/{slug}/transcription/<string:identifier>/': CustomAPIResource, '/{slug}.schema.json': SchemaAPIResource } # Get all slugs from json schema files - use the config json schema # files as the schema source of truth - if a config file is deleted # it can then persist in the mongo collection for data versioning # But will not be available via the API for slug in Schema().list_files(app.config['SCHEMA_DIR']).keys(): for endpoint, resource in resources.items(): slugged_endpoint = endpoint.format(slug=slug) yield slug, slugged_endpoint, resource
def get(self): """ List records :return: --- description: List {slug} records --- """ pagination = pagination_parser() # Convert page and limit to skip and limit query_args = dict(limit=pagination['limit']) # If page is greater than 1, then skip x records if pagination['page'] > 1: query_args['skip'] = (pagination['page'] - 1) * pagination['limit'] # Query MongoDB - gets result cursor cursor = Collection(self.slug).find(**query_args) # Return JSON dict of records and total # Explicity pass through jsonify so it uses custom JSONEncoder return jsonify({ 'total': cursor.count(), 'schema': Schema().load(self.slug), 'records': list(cursor) })
def __init__(self, slug): """ Load the schema for the record :param slug: Schema slog """ self.slug = slug self.schema = Schema().load(self.slug) self.collection = Collection(slug)
def get(self, identifier): """ :param identifier: :return: --- description: Returns a {slug} record --- """ return jsonify({ 'schema': Schema().load(self.slug), 'record': self.doc.read(identifier) })
def get(self): """ Get one record that has not yet been transcribed :return: --- description: List {slug} records --- """ # Prevent multiple people working on same doc limit = 10 skip = random.randint(1, limit) # Query MongoDB - gets result cursor record = Collection(self.slug).find().sort('transcription_count', pymongo.DESCENDING).limit(limit).skip(skip) # Return JSON dict of records and total # Explicity pass through jsonify so it uses custom JSONEncoder return jsonify({ 'total': 1 if record else 0, 'schema': Schema().load(self.slug), 'record': record[0] })
def get(): schemas = Schema().load_all() return jsonify(schemas)
def get(self): schema = Schema().load(self.slug) return jsonify(schema)
def before_first_request(): # On start up, parse, validate and load schemas app.logger.info('Before first request: initiating schema') Schema().build()