class FileLinksSchema(Schema): """Schema for a record's links.""" self_ = Link( template=URITemplate("/api/mocks/{pid_value}/files/{key}"), permission="read", params=lambda record_file: { 'pid_value': record_file.record.pid.pid_value, 'key': record_file.key, }, data_key="self" # To avoid using self since is python reserved key ) content = Link( template=URITemplate("/api/mocks/{pid_value}/files/{key}/content"), permission="read", params=lambda record_file: { 'pid_value': record_file.record.pid.pid_value, 'key': record_file.key, }, ) commit = Link( template=URITemplate("/api/mocks/{pid_value}/files/{key}/commit"), permission="read", params=lambda record_file: { 'pid_value': record_file.record.pid.pid_value, 'key': record_file.key, }, )
class FileLinksSchema(Schema): """Schema for a record file's links.""" self_ = Link( template=URITemplate("/api/records/{pid_value}/files/{key}"), permission="read", params=lambda record_file: { 'pid_value': record_file.record.pid.pid_value, 'key': record_file.key, }, data_key="self" # To avoid using self since is python reserved key ) # TODO: Explore how to expose also the HTTP method # commit = { # "href": URITemplate("/api/records/{pid_value}/files/{key}/commit"), # "method": "POST", # } content = Link( template=URITemplate("/api/records/{pid_value}/files/{key}/content"), permission="read", params=lambda record_file: { 'pid_value': record_file.record.pid.pid_value, 'key': record_file.key, }, ) commit = Link( template=URITemplate("/api/records/{pid_value}/files/{key}/commit"), permission="read", params=lambda record_file: { 'pid_value': record_file.record.pid.pid_value, 'key': record_file.key, }, )
def __new__(mcs, attrs, record_type_name, endpoint_route): """Object creation.""" # TODO better template building ? url_template = f"/api{endpoint_route}" + "/{?params*}" mcs.name = f"{record_type_name}SearchLinksSchema" attrs.update( { "self": Link( template=URITemplate(url_template), permission="search", params=search_link_params(0), ), "prev": Link( template=URITemplate(url_template), permission="search", params=search_link_params(-1), when=search_link_when(-1), ), "next": Link( template=URITemplate(url_template), permission="search", params=search_link_params(+1), when=search_link_when(+1), ), } ) return super().__new__(mcs, mcs.name, (), attrs)
class DraftLinksSchema(Schema): """Schema for a draft's links.""" self = Link(template=URITemplate("/api/mocks/{pid_value}/draft"), permission="read", params=lambda draft: {'pid_value': draft.pid.pid_value}) publish = Link( template=URITemplate("/api/mocks/{pid_value}/draft/actions/publish"), permission="publish", params=lambda draft: {'pid_value': draft.pid.pid_value})
class BibliographicUserRecordsSearchLinksSchemaV1(SearchLinksSchema): """User Record Links schema.""" self = Link(template=URITemplate("/api/user/records{?params*}"), permission="search", params=search_link_params(0)) prev = Link(template=URITemplate("/api/user/records{?params*}"), permission="search", params=search_link_params(-1), when=search_link_when(-1)) next = Link(template=URITemplate("/api/user/records{?params*}"), permission="search", params=search_link_params(+1), when=search_link_when(+1))
class BibliographicRecordLinksSchemaV1(RecordLinksSchema): """Record Links schema.""" # WARNING: It was intentionally decided that if # config.py::RECORDS_UI_ENDPOINTS is changed by the instance, # the instance also needs to overwrite this Schema (in the # links_config) self_html = Link(template=URITemplate("/records/{pid_value}"), permission="read", params=lambda record: {'pid_value': record.pid.pid_value}) files = Link(template=URITemplate("/api/records/{pid_value}/files"), permission="read", params=lambda record: {'pid_value': record.pid.pid_value})
class RecordLinksSchema(Schema): """Schema for a record's links.""" # NOTE: # - /api prefix is needed here because above are mounted on /api self_ = Link( template=URITemplate("/api/mocks/{pid_value}"), permission="read", params=lambda record: {'pid_value': record.pid.pid_value}, data_key="self" # To avoid using self since is python reserved key ) files = Link( template=URITemplate("/api/mocks/{pid_value}/files"), permission="read", params=lambda record: {'pid_value': record.pid.pid_value}, )
class RecordLinksSchema(Schema): """Schema for a record's links.""" self = Link( template=URITemplate("/api/records/{pid_value}"), permission="read", params=lambda record: {'pid_value': record.pid.pid_value} )
class SearchLinksSchema(Schema): """Schema for a search result's links.""" # NOTE: # - /api prefix is needed here because api routes are mounted on /api self = Link( template=URITemplate("/api/mocks{?params*}"), permission="search", params=search_link_params(0), ) prev = Link(template=URITemplate("/api/mocks{?params*}"), permission="search", params=search_link_params(-1), when=search_link_when(-1)) next = Link(template=URITemplate("/api/mocks{?params*}"), permission="search", params=search_link_params(+1), when=search_link_when(+1))
class RecordLinksSchema(Schema): """Schema for a record's links.""" # NOTE: # - /api prefix is needed here because api routes are mounted on /api self = Link( template=URITemplate("/api/records/{pid_value}"), permission="read", params=lambda record: {'pid_value': record.pid.pid_value} )
class BibliographicRecordFilesLinksSchema(Schema): """Schema for files list links.""" self_ = Link( template=URITemplate("/api/records/{pid_value}/files"), permission="read", params=lambda record: { 'pid_value': record.pid.pid_value, }, data_key="self" # To avoid using self since is python reserved key )
class VocabularyLinksSchema(Schema): """Schema for a record's links.""" # NOTE: # - /api prefix is needed here because above are mounted on /api self = Link( template=URITemplate( "/api/vocabularies/{vocabulary_type}/{pid_value}"), permission="read", params=lambda record: { "pid_value": record.pid.pid_value, "vocabulary_type": record.vocabulary_type or record.get('vocabulary_type') }, data_key="self", # To avoid using self since is python reserved key )
def __new__(mcs, attrs, record_type_name, endpoint_route): """Object creation.""" mcs.name = f"{record_type_name}LinksSchema" # TODO better template building ? url_template = f"/api{endpoint_route}" + "/{pid_value}" attrs.update({ "self": Link( template=URITemplate(url_template), permission="read", params=lambda record: { "pid_value": record.pid.pid_value, }, data_key="self", # To avoid using self since is python reserved key ) }) return super().__new__(mcs, mcs.name, (), attrs)