forked from inveniosoftware/cookiecutter-invenio-instance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
serializers: add record link factory
* Closes inveniosoftware#172
- Loading branch information
Showing
5 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
{{cookiecutter.project_shortname}}/{{cookiecutter.package_name}}/records/links/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2019 CERN. | ||
# | ||
# My site is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Module for defining link factories""" | ||
|
||
from __future__ import absolute_import, print_function |
33 changes: 33 additions & 0 deletions
33
...kiecutter.project_shortname}}/{{cookiecutter.package_name}}/records/links/record_links.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2019 CERN. | ||
# | ||
# My site is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
from __future__ import absolute_import, print_function | ||
|
||
from flask import url_for, g | ||
|
||
from invenio_records_rest.proxies import current_records_rest | ||
|
||
|
||
def record_links_factory(pid, record=None, **kwargs): | ||
"""Factory for record links generation. | ||
:param pid: A Persistent Identifier instance. | ||
:returns: Dictionary containing a list of useful links for the record. | ||
""" | ||
# Load pid in the global context for the url construction | ||
g.pid = pid.pid_value | ||
record_endpoint = '.{0}_item'.format( | ||
current_records_rest.default_endpoint_prefixes[pid.pid_type]) | ||
links = dict( | ||
self=url_for(record_endpoint, pid_value=pid.pid_value, _external=True), | ||
files=url_for( | ||
'invenio_records_files.bucket_api', | ||
pid_value=pid.pid_value, | ||
_external=True | ||
) | ||
) | ||
return links |