Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to exclude a field? #29

Closed
remillc opened this issue Nov 7, 2022 · 2 comments
Closed

How to exclude a field? #29

remillc opened this issue Nov 7, 2022 · 2 comments
Labels
support issue Technical issue in using the software

Comments

@remillc
Copy link

remillc commented Nov 7, 2022

We need to remove the "Extra" field from the search index and the result display:

2022-11-07 12-31-07

Is it possible? How do I proceed?

@davidlesieur
Copy link
Member

For this type of customization, there are two separate aspects to consider: (1) search and (2) display.

(1) You'll want the Extra field to be excluded from searches. For that, you may use the KERKOAPP_EXCLUDE_DEFAULT_FIELDS variable. In Kerko's database schema, the searchable text field is called z_extra. Thus, in your .env file, it might look like:

KERKOAPP_EXCLUDE_DEFAULT_FIELDS="z_extra"

(2) Next, excluding the field from display requires you to customize KerkoApp and to override Kerko's default item template. To do so:

  • Create a new directory under KerkoApp's app/templates directory, e.g., app/templates/custom-templates. Then create a new file called item.html.jinja2 in that directory.
  • In KerkoApp's app/config.py, near the end of the __init__() method, add the add the following line to use the new template:
    KERKO_TEMPLATE_ITEM = 'custom-templates/item.html.jinja2'
    
  • Edit the content of your new item.html.jinja2 to override the template block that needs to be replaced. It should look like:
    {% extends 'kerko/item.html.jinja2' %}
    
    {% block item_fields_zotero %}
        {#- Display item fields in proper order. #}
        {%- for f in item.item_fields %}
            {%- if item.data[f.field] %}
                {%- if f.field == 'accessDate' %}
                    {{- field(f.localized, item.data[f.field]|kerko_reformat_date(convert_tz=True)|escape) }}
                {%- elif f.field in ['date', 'dateDecided', 'dateEnacted', 'filingDate', 'issueDate'] %}
                    {{- field(f.localized, item.data[f.field]|kerko_reformat_date|escape) }}
                {%- elif f.field == 'DOI' %}
                    {{- field(f.localized, item.data[f.field]|escape|kerko_urlize_doi(target='_blank')) }}
                {%- elif f.field != 'extra' %}  {# CUSTOMIZATION: Exclude the 'extra' field. #}
                    {{- field(f.localized, item.data[f.field]|escape|urlize(target='_blank'), value_class='pre-line' if f.field == 'abstractNote') }}
                {%- endif %}
            {%- endif %}
        {%- endfor %}
    {% endblock item_fields_zotero %}
    

Here, I took the block's content from Kerko's own item.html.jinja2, and changed just the part that deals with the Extra field.

In the future, when upgrading to a new Kerko version, you'll then have to pay attention to changes to the item_fields_zotero block in Kerko's default item.html.jinja2, in case you want to replicate the same changes in your custom version. To help with this, it may be useful to mark customizations with a comment, as in my above example.

Kerko's documentation on customization is still a bit lacking at the moment. I'm delaying its writing because I hope to develop a plugin system that should facilitate customization. If all goes according to plan, that may happen sometime in 2023. In the meantime, I hope this answer will be useful!

@davidlesieur davidlesieur added the support issue Technical issue in using the software label Nov 8, 2022
@remillc
Copy link
Author

remillc commented Nov 9, 2022

Yes this answer has been useful! It worked with this modification:

In KerkoApp's app/config.py, near the end of the __init__() method, add the add the following line to use the new template:
KERKO_TEMPLATE_ITEM = 'custom-templates/item.html.jinja2'

The line should be changed to:

self.KERKO_TEMPLATE_ITEM = 'custom-templates/item.html.jinja2'

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support issue Technical issue in using the software
Projects
None yet
Development

No branches or pull requests

2 participants