Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
resource types shown as badges in promoted
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Souhei committed Oct 10, 2024
1 parent c1a9db1 commit c1dbf7b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ckanext/zarr/assets/css/zarr.css
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,7 @@
font-size: 14px;
}

.dataset.promoted-background .promoted-container .badge {
margin-right: 5px;
}

23 changes: 23 additions & 0 deletions ckanext/zarr/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime, timedelta
from ckan.plugins import toolkit
import html
from ckanext.scheming.helpers import scheming_get_dataset_schema


def get_user_obj(field=""):
Expand Down Expand Up @@ -104,3 +105,25 @@ def lower_formatter(input):

def month_formatter(month):
return datetime.strptime(month, "%Y-%m").strftime("%b %Y")


def get_dataset_resource_type_groups(id, dataset_type='dataset'):
dataset = toolkit.get_action('package_show')(
data_dict={'id': id}
)
groups = dataset.get('groups', [])
if not groups:
return []
groups = [group['name'] for group in groups]
choices = None
schema = scheming_get_dataset_schema(dataset_type)
for field in schema['dataset_fields']:
if field['field_name'] == 'resource_type':
choices = field['choices']
if choices:
return [
choice['label']
for choice in choices
if choice['value'] in groups
]
return []
3 changes: 2 additions & 1 deletion ckanext/zarr/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def get_helpers(self):
'get_all_groups': zarr_helpers.get_all_groups,
'get_user_from_id': zarr_helpers.get_user_from_id,
'get_user_obj': zarr_helpers.get_user_obj,
'month_formatter': zarr_helpers.month_formatter
'month_formatter': zarr_helpers.month_formatter,
'get_dataset_resource_type_groups': zarr_helpers.get_dataset_resource_type_groups
}

# IConfigurer
Expand Down
60 changes: 58 additions & 2 deletions ckanext/zarr/templates/package/base.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
{% ckan_extends %}

{% block fx_bg %}{% endblock %}
{% block promoted_toolbar %}

{% block fx_container %}
<div class="dataset promoted-background promoted-breadcrumbs">
<div class="flag-vertical-bars">
<div class="flag-bar flag-green"></div>
<div class="flag-bar flag-red"></div>
<div class="flag-bar flag-black"></div>
<div class="flag-bar flag-orange"></div>
</div>
<div class="container">
<div class="toolbar" role="navigation" aria-label="{{ _('Breadcrumb') }}">
<div class="container">
<div class="promoted">
<div class="promoted-container container">
<div class="package-subtitle-and-action">
<div class="mini-breadcrumb">
{%- if not pkg -%}
<p class="subtitle"> {{_('Home')}} / {{_(dataset_type)}} </p>
{%- else -%}
{%- set dataset_type_title = h.scheming_get_dataset_schema(pkg.type).get('name', pkg.type) -%}
<p class="subtitle"> {{_('Home')}} / {{_(dataset_type_title)}} </p>
{% endif %}
</div>
{%- if pkg -%}
<div class="manage-button">
<div class="content_action">
{% block content_action %}{% endblock %}
</div>
</div>
{% endif %}
</div>

{%- if not pkg -%}
<h1 class="headline">{{_('New {dataset_type}').format(dataset_type=dataset_type)}}</h1>
{%- else -%}
<h1 class="headline">{% link_for pkg.title, named_route=pkg.type ~ '.read', id=pkg.name, title=pkg.title %}</h1>
{% if pkg.private %}
<span class="dataset-private badge badge-inverse">
<i class="fa fa-lock"></i>
{{ _('Private') }}
</span>
{% endif %}
{% set resource_type_labels = h.get_dataset_resource_type_groups(pkg.id) %}
{% for label in resource_type_labels %}
<span class="badge">{{ label }}</span>
{% endfor %}
<div class="description">
{%- set notes = h.render_markdown(h.get_translated(pkg, 'notes')) -%}
{{ notes | truncate(430)}}
{%- if notes | length > 430 -%}
<a class="read-more" href="{% url_for pkg.type ~ '.read', id=pkg.name %}#dataset-description">{{_('Read More')}}</a>
{%- endif -%}
</div>
{%- endif -%}
</div>
</div>
</div>
</div>
{%- if pkg -%}
<ul class="nav nav-tabs">
{% block content_primary_nav %}{% endblock %}
</ul>
{%- endif -%}
</div>
</div>
{% endblock %}

0 comments on commit c1dbf7b

Please sign in to comment.