def test_get_endpoint_from_record_supports_relative_urls(): expected = 'authors' record = { '$schema': 'schemas/records/authors.json' } result = get_endpoint_from_record(record) assert expected == result
def test_get_endpoint_from_record(): expected = 'literature' record = { '$schema': 'http://localhost:5000/schemas/records/hep.json' } result = get_endpoint_from_record(record) assert expected == result
def update_links(record, old_ref, new_ref): def _update_links(record, parts, old_ref, new_ref): for i, part in enumerate(parts): if isinstance(record, dict): try: record = record[part] except KeyError: return elif isinstance(record, list): for el in record: _update_links(el, parts[i:], old_ref, new_ref) return if record['$ref'] == old_ref: record['$ref'] = new_ref endpoint = get_endpoint_from_record(record) whitelist = current_app.config['INSPIRE_REF_UPDATER_WHITELISTS'][endpoint] for path in whitelist: _update_links(record, path.split('.'), old_ref, new_ref)
def update_links(record, old_ref, new_ref): def _update_links(record, parts, old_ref, new_ref): for i, part in enumerate(parts): if isinstance(record, dict): try: record = record[part] except KeyError: return elif isinstance(record, list): for el in record: _update_links(el, parts[i:], old_ref, new_ref) return if record['$ref'] == old_ref: record['$ref'] = new_ref endpoint = get_endpoint_from_record(record) whitelist = current_app.config['INSPIRE_REF_UPDATER_WHITELISTS'][endpoint] for path in whitelist: _update_links(record, path.split('.'), old_ref, new_ref)
def preview(): """Preview the record being edited.""" record = request.get_json() endpoint = get_endpoint_from_record(record) template = current_app.config['RECORDS_UI_ENDPOINTS'][endpoint]['template'] return render_template(template, record=record)
def preview(): """Preview the record being edited.""" record = request.get_json() endpoint = get_endpoint_from_record(record) template = current_app.config['RECORDS_UI_ENDPOINTS'][endpoint]['template'] return render_template(template, record=record)