def deposits_edit(pid_value): """Deposit edit page.""" links_config = BibliographicDraftResourceConfig.links_config draft = service.read_draft(id_=pid_value, identity=g.identity, links_config=links_config) files_service = BibliographicDraftFilesService() files_list = files_service.list_files( id_=pid_value, identity=g.identity, links_config=BibliographicDraftFilesResourceConfig.links_config) forms_config = dict(apiUrl=f"/api/records/{pid_value}/draft", vocabularies=Vocabularies.dump(), current_locale=str(current_i18n.locale)) # Dereference relations (languages, licenses, etc.) draft._record.relations.dereference() # TODO: get the `is_published` field when reading the draft _record = draft.to_dict() from invenio_pidstore.errors import PIDUnregistered try: _ = service.draft_cls.pid.resolve(pid_value, registered_only=True) _record["is_published"] = True except PIDUnregistered: _record["is_published"] = False searchbar_config = dict(searchUrl=search_url) return render_template( current_app.config['DEPOSITS_FORMS_BASE_TEMPLATE'], forms_config=forms_config, record=_record, files=files_list.to_dict(), searchbar_config=searchbar_config)
def get_form_config(**kwargs): """Get the react form configration.""" return dict( vocabularies=Vocabularies.dump(), current_locale=str(current_i18n.locale), **kwargs )
def test_dump_contributors_role(config, vocabulary_clear): prev_config = config.get('RDM_RECORDS_CUSTOM_VOCABULARIES') config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = { 'contributors.role': { 'path': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'contributor_role.csv') }, } dumped_vocabularies = Vocabularies.dump() assert dumped_vocabularies['contributors']['role'] == [{ 'value': 'Librarian', 'text': _('Librarian') }, { 'value': 'DataCollector', 'text': _('Data Collector') }] config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = prev_config
def deposits_create(): """Record creation page.""" forms_config = dict(apiUrl='/api/records/', vocabularies=Vocabularies.dump()) searchbar_config = dict(searchUrl='/search') empty_record = dump_empty(MetadataSchemaV1) return render_template(current_app.config['DEPOSITS_FORMS_BASE_TEMPLATE'], forms_config=forms_config, record=empty_record, searchbar_config=searchbar_config)
def deposits_create(): """Record creation page.""" forms_config = dict( createUrl=("/api/records"), vocabularies=Vocabularies.dump(), ) return render_template( current_app.config['DEPOSITS_FORMS_BASE_TEMPLATE'], forms_config=forms_config, record=dump_empty(RDMRecordSchema), searchbar_config=dict(searchUrl=search_url))
def get_form_config(**kwargs): """Get the react form configuration.""" vocabularies = Vocabularies.dump() vocabularies["resource_type"] = _dump_resource_type_vocabulary() vocabularies["titles"] = dict( type=_dump_title_types_vocabulary() ) return dict( vocabularies=vocabularies, current_locale=str(current_i18n.locale), pids=get_form_pids_config(), **kwargs )
def deposits_create(): """Record creation page.""" forms_config = dict(createUrl=("/api/records"), vocabularies=Vocabularies.dump(), current_locale=str(current_i18n.locale)) return render_template( current_app.config['DEPOSITS_FORMS_BASE_TEMPLATE'], forms_config=forms_config, record=dump_empty(RDMRecordSchema), files=dict(default_preview=None, enabled=True, entries=[], links={}), searchbar_config=dict(searchUrl=search_url))
def test_dump_resource_type(config, vocabulary_clear): prev_config = config.get('RDM_RECORDS_CUSTOM_VOCABULARIES') config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = { 'resource_type': { 'path': os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', 'resource_types.csv' ) }, } dumped_vocabularies = Vocabularies.dump() assert dumped_vocabularies['resource_type'] == { 'type': [ { 'icon': 'file alternate', 'text': _('Publication'), 'value': 'publication', }, { 'icon': 'chart bar outline', 'text': _('Image'), 'value': 'my_image', }, { 'icon': 'code', 'text': _('Software'), 'value': 'software', } ], 'subtype': [ { 'parent-text': _('Publication'), 'parent-value': 'publication', 'text': _('Book'), 'value': 'publication-book', }, { 'parent-text': _('Image'), 'parent-value': 'my_image', 'text': _('Photo'), 'value': 'my_photo', } ] } config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = prev_config
def deposits_edit(pid_value): """Deposit edit page.""" links_config = BibliographicDraftResourceConfig.links_config draft = service.read_draft(id_=pid_value, identity=g.identity, links_config=links_config) forms_config = dict(apiUrl=f"/api/records/{pid_value}/draft", vocabularies=Vocabularies.dump()) searchbar_config = dict(searchUrl=search_url) return render_template( current_app.config['DEPOSITS_FORMS_BASE_TEMPLATE'], forms_config=forms_config, record=draft.to_dict(), searchbar_config=searchbar_config)
def get_form_config(**kwargs): """Get the react form configuration.""" vocabularies = Vocabularies.dump() vocabularies["resource_type"] = _dump_resource_type_vocabulary() vocabularies["titles"] = dict(type=_dump_title_types_vocabulary()) vocabularies["creators"] = dict(role=_dump_creators_role_vocabulary()) vocabularies["contributors"] = dict( role=_dump_contributors_role_vocabulary()) vocabularies["descriptions"] = dict( type=_dump_description_types_vocabulary()) vocabularies["dates"] = dict(type=_dump_date_types_vocabulary()) vocabularies["relation_type"] = _dump_relation_types_vocabulary() return dict(vocabularies=vocabularies, current_locale=str(current_i18n.locale), pids=get_form_pids_config(), **kwargs)
def test_dump_titles_type(config, vocabulary_clear): prev_config = config.get('RDM_RECORDS_CUSTOM_VOCABULARIES') config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = { 'titles.type': { 'path': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'title_type.csv') } } dumped_vocabularies = Vocabularies.dump() assert dumped_vocabularies['titles']['type'] == [{ 'value': 'AlternateTitle', 'text': _('Alternate Title') }] config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = prev_config
def test_dump_access_right(config, vocabulary_clear): prev_config = config.get('RDM_RECORDS_CUSTOM_VOCABULARIES') config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = { 'access_right': { 'path': os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', 'access_right.csv' ) } } dumped_vocabularies = Vocabularies.dump() assert dumped_vocabularies['access_right'] == [ { 'icon': 'lock open', 'value': 'open', 'text': _('Open Access') }, ] config['RDM_RECORDS_CUSTOM_VOCABULARIES'] = prev_config
def deposits_edit(id): """Fake deposits edit page.""" forms_config = dict(apiUrl='/api/records/', vocabularies=Vocabularies.dump()) # minimal record record = { "_access": { "metadata_restricted": False, "files_restricted": False }, "_owners": [1], "_created_by": 1, "access_right": "open", "id": "{}".format(id), "resource_type": { "type": "image", "subtype": "image-photo" }, # Technically not required "creators": [], "titles": [{ "title": "A Romans story", "type": "Other", "lang": "eng" }], "links": { "edit": "/deposits/{}/edit".format(id) } } searchbar_config = dict(searchUrl='/search') initial_record = dump_empty(MetadataSchemaV1) initial_record.update(record) return render_template(current_app.config['DEPOSITS_FORMS_BASE_TEMPLATE'], forms_config=forms_config, record=initial_record, searchbar_config=searchbar_config)