diff --git a/ldcoolp/config/default.ini b/ldcoolp/config/default.ini index 24e2ae1..30b6d69 100644 --- a/ldcoolp/config/default.ini +++ b/ldcoolp/config/default.ini @@ -46,6 +46,10 @@ report_url = https://bit.ly/ReDATA_CurationTemplate # README template filename located in curation.inspection.readme readme_template = README_template.md +# Macros for README located in curation.inspection.readme.template +macros_folder = macros +funders_macro = ***override*** + # For logging log_parent_dir = %(parent_dir)s log_dir = logs diff --git a/ldcoolp/curation/inspection/readme/__init__.py b/ldcoolp/curation/inspection/readme/__init__.py index c9abd71..1589625 100644 --- a/ldcoolp/curation/inspection/readme/__init__.py +++ b/ldcoolp/curation/inspection/readme/__init__.py @@ -7,6 +7,7 @@ # Template engine from jinja2 import Environment, FileSystemLoader +from jinja2.ext import loopcontrols from html2text import html2text # Logging @@ -125,6 +126,7 @@ def __init__(self, dn: DepositorName, config_dict=config_default_dict, self.curation_dict = self.config_dict['curation'] self.root_directory_main = self.curation_dict[self.curation_dict['parent_dir']] + self.funders_macro = join(self.curation_dict['macros_folder'], self.curation_dict['funders_macro']) # Always obtain current data curation stage self.mc = move.MoveClass(curation_dict=self.curation_dict) @@ -260,6 +262,10 @@ def save_template(self): dest_file = join(self.metadata_path, self.readme_template) + funders_macro_file_src = join(dirname(__file__), 'templates', + self.funders_macro) + funders_macro_file_dest = join(self.metadata_path, self.curation_dict['funders_macro']) + if not exists(dest_file): self.log.info(f"Saving {self.readme_template} template in METADATA ...") @@ -271,6 +277,7 @@ def save_template(self): self.log.info(f"Source file name: {src_file}") shutil.copy(src_file, dest_file) + shutil.copy(funders_macro_file_src, funders_macro_file_dest) else: self.log.info(f"{dest_file} exists. Not overwriting template!") @@ -283,7 +290,7 @@ def import_template(self): """Returns a jinja2 template by importing README markdown template (README_template.md)""" file_loader = FileSystemLoader(self.metadata_path) - env = Environment(loader=file_loader, lstrip_blocks=True, trim_blocks=True) + env = Environment(loader=file_loader, lstrip_blocks=True, trim_blocks=True, extensions=[loopcontrols]) jinja_template = env.get_template(self.default_readme_file) return jinja_template @@ -365,9 +372,15 @@ def retrieve_article_metadata(self): self.log.info("No footer to strip") readme_dict['description'] = description + # Retrieve funder details as a list of dicts + readme_dict['funders'] = self.article_dict['item']['funding_list'] + # Retrieve references as list readme_dict['references'] = self.article_dict['item']['references'] + # Retrieve related materials as a list of dicts + readme_dict['related_materials'] = self.article_dict['item']['related_materials'] + return readme_dict def retrieve_qualtrics_readme(self): diff --git a/ldcoolp/curation/inspection/readme/templates/DVC.md b/ldcoolp/curation/inspection/readme/templates/DVC.md index 31b8836..e9bea89 100644 --- a/ldcoolp/curation/inspection/readme/templates/DVC.md +++ b/ldcoolp/curation/inspection/readme/templates/DVC.md @@ -42,6 +42,22 @@ DOI: +{% endif %} +{% if figshare_dict.funders != [] %} +--------------------------------------------- +## Funding Information + +{% import 'funders_macro.jinja' as funds %} +{% for funder in figshare_dict.funders -%} +{% if funder.is_user_defined == 0 -%} +{{ funds.funders_(funder) }} +{% else %} +- {{ funder.title }} +{% endif %} +{%- endfor %} + + + {% endif %} {% if qualtrics_dict.files != 'nan' %} --------------------------------------------- @@ -87,9 +103,9 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/ This item is part of the University of Arizona Libraries 2021 Data Visualization Challenge, which is available here: https://doi.org/10.25422/azu.data.c.5405493 -{% if figshare_dict.references != [] %} -Links: -{% for reference in figshare_dict.references %} - - {{ reference }} +{% if figshare_dict.related_materials != [] %} +Related Materials: +{% for material in figshare_dict.related_materials %} + - {{ material.relation }}: {{ material.title }} ({{ material.link }}) {% endfor -%} {% endif %} \ No newline at end of file diff --git a/ldcoolp/curation/inspection/readme/templates/Main.md b/ldcoolp/curation/inspection/readme/templates/Main.md index 128cc1d..22917eb 100755 --- a/ldcoolp/curation/inspection/readme/templates/Main.md +++ b/ldcoolp/curation/inspection/readme/templates/Main.md @@ -43,6 +43,22 @@ DOI: +{% endif %} +{% if figshare_dict.funders != [] %} +--------------------------------------------- +## Funding Information + +{% import 'funders_macro.jinja' as funds %} +{% for funder in figshare_dict.funders -%} +{% if funder.is_user_defined == 0 -%} +{{ funds.funders_(funder) }} +{% else %} +- {{ funder.title }} +{% endif %} +{%- endfor %} + + + {% endif %} {% if qualtrics_dict.files != 'nan' %} --------------------------------------------- @@ -87,7 +103,7 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/ {% endif %} {% endif %} -{% if qualtrics_dict.notes != 'nan' or figshare_dict.references != [] %} +{% if qualtrics_dict.notes != 'nan' or figshare_dict.related_materials != [] %} --------------------------------------------- ## Additional Notes @@ -96,9 +112,9 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/ {{ qualtrics_dict.notes }} {% endif %} -{% if figshare_dict.references != [] %} -Links: -{% for reference in figshare_dict.references %} - - {{ reference }} +{% if figshare_dict.related_materials != [] %} +Related Materials: +{% for material in figshare_dict.related_materials %} + - {{ material.relation }}: {{ material.title }} ({{ material.link }}) {% endfor -%} {% endif %} diff --git a/ldcoolp/curation/inspection/readme/templates/Space_Grant.md b/ldcoolp/curation/inspection/readme/templates/Space_Grant.md index 83a3008..29c6184 100644 --- a/ldcoolp/curation/inspection/readme/templates/Space_Grant.md +++ b/ldcoolp/curation/inspection/readme/templates/Space_Grant.md @@ -43,6 +43,22 @@ DOI: +{% endif %} +{% if figshare_dict.funders != [] %} +--------------------------------------------- +## Funding Information + +{% import 'funders_macro.jinja' as funds %} +{% for funder in figshare_dict.funders -%} +{% if funder.is_user_defined == 0 -%} +{{ funds.funders_(funder) }} +{% else %} +- {{ funder.title }} +{% endif %} +{%- endfor %} + + + {% endif %} {% if qualtrics_dict.files != 'nan' %} --------------------------------------------- @@ -96,10 +112,10 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/ {{ qualtrics_dict.notes }} {% endif %} -{% if figshare_dict.references != [] %} -Links: -{% for reference in figshare_dict.references %} - - {{ reference }} +{% if figshare_dict.related_materials != [] %} +Related Materials: +{% for material in figshare_dict.related_materials %} + - {{ material.relation }}: {{ material.title }} ({{ material.link }}) {% endfor -%} {% endif %} diff --git a/ldcoolp/curation/inspection/readme/templates/WCCFL.md b/ldcoolp/curation/inspection/readme/templates/WCCFL.md index b0fd2cb..b609285 100644 --- a/ldcoolp/curation/inspection/readme/templates/WCCFL.md +++ b/ldcoolp/curation/inspection/readme/templates/WCCFL.md @@ -43,6 +43,22 @@ DOI: +{% endif %} +{% if figshare_dict.funders != [] %} +--------------------------------------------- +## Funding Information + +{% import 'funders_macro.jinja' as funds %} +{% for funder in figshare_dict.funders -%} +{% if funder.is_user_defined == 0 -%} +{{ funds.funders_(funder) }} +{% else %} +- {{ funder.title }} +{% endif %} +{%- endfor %} + + + {% endif %} {% if qualtrics_dict.files != 'nan' %} --------------------------------------------- @@ -96,10 +112,10 @@ The roles are defined by the CRediT taxonomy http://credit.niso.org/ {{ qualtrics_dict.notes }} {% endif %} -{% if figshare_dict.references != [] %} -Links: -{% for reference in figshare_dict.references %} - - {{ reference }} +{% if figshare_dict.related_materials != [] %} +Related Materials: +{% for material in figshare_dict.related_materials %} + - {{ material.relation }}: {{ material.title }} ({{ material.link }}) {% endfor -%} {% endif %} diff --git a/ldcoolp/curation/inspection/readme/templates/macros/funders_macro.jinja b/ldcoolp/curation/inspection/readme/templates/macros/funders_macro.jinja new file mode 100644 index 0000000..ff7d53e --- /dev/null +++ b/ldcoolp/curation/inspection/readme/templates/macros/funders_macro.jinja @@ -0,0 +1,28 @@ +{% macro funders_(given_funder) -%} + {% set funders = { + 'National Science Foundation': ['Directorate for Biological Sciences', + 'Directorate for Computer and Information Science and Engineering', + 'Directorate for Engineering', + 'Directorate of Geosciences', + 'Directorate for Mathematical and Physical Sciences', + 'Directorate for Social, Behavioral and Economic Sciences', + 'Directorate for STEM Education', + 'Directorate for Technology, Innovation and Partnerships' + ] + } %} +{% set ns = namespace(given_funder_found = false) %} +{% for funder, offices in funders.items() -%} +{% if given_funder.funder_name in offices -%} +{% set ns.given_funder_found = true %} +- {{ funder }} (Grant no: {{ given_funder.grant_code }}) + {{ given_funder.url }} +{% break %} +{% else %} +{% set ns.given_funder_found = false %} +{%- endif %} +{%- endfor %} +{% if ns.given_funder_found == false -%} +- {{ given_funder.funder_name}} (Grant no: {{ given_funder.grant_code }}) + {{ given_funder.url }} +{%- endif %} +{%- endmacro %} \ No newline at end of file