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

Refactor template paths for dataset read views to simplify structure #121

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ckanext/schemingdcat/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ class SchemingDCATDatasetsPlugin(SchemingDatasetsPlugin):
p.implements(p.IValidators)

def read_template(self):
return "schemingdcat/package/read.html"
return "package/read.html"

def resource_template(self):
return "schemingdcat/package/resource_read.html"
return "package/resource_read.html"

def package_form(self):
return "schemingdcat/package/snippets/package_form.html"
Expand Down
85 changes: 85 additions & 0 deletions ckanext/schemingdcat/templates/package/read.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{% extends "package/read_base.html" %}

{%- set schema = h.schemingdcat_get_cached_schema(dataset_type) -%}

{% block primary_content_inner %}
{{ super() }}
{% block package_description %}
<div class="dataset-badges">
{% if pkg.private %}
<span class="dataset-private badge pull-left badge-package">
<i class="fa fa-lock"></i>
{{ _('Private') }}
</span>
{% endif %}
{% if pkg.state.startswith('draft') %}
<span class="dataset-draft badge pull-left">
<i class="fa fa-book"></i>
{{ _('Draft') }}
</span>
{% endif %}
{% if pkg.state == 'deleted' %}
<span class="dataset-delete badge badge pull-left">
<i class="fa fa-trash"></i>
{{ _('Deleted') }}
</span>
{% endif %}
{% if pkg.schemingdcat_xls_metadata_template %}
<span class="dataset-draft badge pull-left">
<a href="{{ h.url_for('schemingdcat.metadata_templates') }}" title="{{ _('Metadata templates') }}">
<i class="fa fa-table"></i> {{ _('Metadata template') }}
</a>
</span>
{% endif %}
</div>
<h1>
{% block page_heading %}
{{ h.dataset_display_name(pkg) }}
{% endblock %}
</h1>
{% block package_notes %}
{% if not dataset_type %}
<p>
dataset_type not passed to template. your version of CKAN
might not be compatible with ckanext-scheming
</p>
{% endif %}
{% if (h.scheming_field_by_name(schema.dataset_fields, 'notes') or
h.scheming_field_by_name(schema.dataset_fields, 'notes_translated')) and
pkg.notes %}
<div class="notes embedded-content package_notes">
{{ h.render_markdown(h.dataset_display_field_value(pkg, 'notes')) }}
</div>
{% endif %}
{% endblock %}
{% endblock %}

{% block package_resources %}
{% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources,
can_edit=h.check_access('package_update', {'id':pkg.id }) %}
{% endblock %}

{% set is_bibliographic_dcat_type = h.schemingdcat_is_bibliographic_dcat_type(pkg.dcat_type) %}
{% if pkg.dataset_scope == 'non_spatial_dataset' and is_bibliographic_dcat_type %}
{% snippet "schemingdcat/snippets/dataset_citation.html", pkg=pkg, dataset_type=dataset_type, schema=schema %}
{% endif %}
{% if pkg.spatial and not is_bibliographic_dcat_type %}
{% block package_dataset_extent %}
{% snippet "schemingdcat/snippets/schemingdcat_dataset_map_additional_info.html", extent=pkg.spatial %}
{% endblock %}
{% endif %}

{% block package_tags %}
{% snippet "schemingdcat/package/snippets/tags.html", tags=pkg.tags %}
{% endblock %}

{% block package_metadata_info %}
{% set is_bibliographic_dcat_type = h.schemingdcat_is_bibliographic_dcat_type(pkg.dcat_type) %}
{% if pkg.dataset_scope == 'non_spatial_dataset' and is_bibliographic_dcat_type %}
{% snippet "schemingdcat/package/snippets/document_info.html", pkg=pkg, dataset_type=dataset_type, schema=schema %}
{% else %}
{% snippet "schemingdcat/package/snippets/metadata_info.html", pkg=pkg, dataset_type=dataset_type, schema=schema %}
{% endif %}
{% endblock %}

{% endblock %}
133 changes: 133 additions & 0 deletions ckanext/schemingdcat/templates/package/resource_read.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{% ckan_extends %}

{% set exclude_fields = [
'name',
'title',
'title_translated',
'description',
'description_translated',
'url',
'rights',
'license',
] %}

{# Fields for snippet schemingdcat/package/snippets/resource_extended_info.html #}
{% set extended_fields = [
'format',
'modified',
'created',
'conforms_to',
'language',
'mimetype',
'reference_system',
'size',
'download_url'
]
%}

{% set schema = h.schemingdcat_get_cached_schema(dataset_type) %}

{% block resource_actions_inner %}
{% block action_manage %}
{% if h.check_access('package_update', {'id':pkg.id }) %}
<li>{% link_for _('Edit resource'), named_route=pkg.type ~ '_resource.edit', id=pkg.name, resource_id=res.id, class_='btn btn-default', icon='pencil' %}</li>
{% block action_manage_inner %}{% endblock %}
<li>{% link_for _('Views'), named_route=pkg.type ~ '_resource.views', id=pkg.name, resource_id=res.id, class_='btn btn-default', icon='chart-bar' %}
{% endif %}
{% endblock action_manage %}
{% if res.url and h.is_url(res.url) %}
<li>
{% if res.datastore_active %}
<li>{% snippet 'schemingdcat/package/snippets/data_api_button.html', resource=res %}</li>
{% endif %}
<div class="btn-group">
{% if res.url and h.is_url(res.url) %}
<a class="btn btn-primary resource-url-analytics" href="{{ res.url }}">
{% if res.resource_type in ('listing', 'service') %}
<i class="fa fa-eye"></i> {{ _('View') }}
{% elif res.resource_type == 'api' %}
<i class="fa fa-key"></i> {{ _('API Endpoint') }}
{% elif res.datastore_active or (not res.has_views and res.url_type == 'upload') %}
<i class="fa fa-download"></i> {{ _('Download') }}
{% elif not res.has_views and not res.url_type == 'upload' %}
<i class="fa fa-external-link"></i> {{ _('Go to resource') }}
{% else %}
<i class="fa fa-external-link"></i> {{ _('Go to resource') }}
{% endif %}
</a>
{% endif %}
{% if not res.resource_type in ('listing', 'service', 'api') and res.datastore_active %}
{% snippet "schemingdcat/package/snippets/download_datastore_formats.html", res=res %}
{% endif %}
</div>
</li>
{% endif %}
{% endblock %}

{% block resource_additional_information_inner %}

{% if res.datastore_active or res.url_type == 'datastore' %}
{% block resource_data_dictionary %}
{% snippet "schemingdcat/package/snippets/resource_datadictionary_info.html", res=res %}
{% endblock %}
{% endif %}

<div class="module-content">
{% block resource_metadata_info %}
{% asset 'ckanext-schemingdcat/schemingdcat-table-collapsible-rows' %}

<h2>{{ _('Distribution metadata') }}</h2>

{# Basic Resource information #}
<table class="table table-bordered table-condensed"
data-module="schemingdcat-table-collapsible-rows"
data-module-numcols="2"
>
<thead class="thead-normal_table">
<tr>
<td scope="row" colspan="2">
{{ _('Basic information') }}
</td>
</tr>
</thead>
{% endblock %}
<tbody>
{% block extended_info %}
{% snippet "schemingdcat/package/snippets/resource_extended_info.html", field=field, res=res, extended_fields=extended_fields, schema=schema %}
{% endblock %}

{% block resource_fields %}
{% for field in schema.resource_fields %}
{% if field.field_name not in exclude_fields
and field.field_name not in extended_fields
and field.display_snippet is not none %}
<tr class="toggle-more">
<th scope="row">{{ h.scheming_language_text(field.label) }}</th>
<td class="dataset-details"{%
if field.display_property %} property="{{ field.display_property
}}"{% endif %}>{% snippet 'scheming/snippets/display_field.html',
field=field, data=res, schema=schema %}</td>
</tr>
{% endif %}
{% endfor %}
{% endblock %}
</tbody>
</table>


</div>
{% endblock %}

{% block secondary_content %}

{% block resources_list %}
{% snippet "package/snippets/resources.html", pkg=pkg, active=res.id, action='read' %}
{% endblock %}

{% block resource_license %}
{% snippet "schemingdcat/snippets/schemingdcat_license.html", pkg_dict=pkg %}
{% endblock %}
{% block access_rights %}
{% snippet "schemingdcat/snippets/access_rights.html", pkg_dict=pkg, schema=schema %}
{% endblock %}
{% endblock %}
Loading
Loading