Skip to content

Commit

Permalink
Merge pull request #169 from c-3lab/fix_data_insertion_in_resource_ad…
Browse files Browse the repository at this point in the history
…ditional_information

リソース詳細情報へのデータ挿入方法の変更
  • Loading branch information
ryo-ma committed May 16, 2024
2 parents 36ff4ec + e02b379 commit eabbaa3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 72 deletions.
34 changes: 33 additions & 1 deletion ckanext/feedback/plugin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
from types import SimpleNamespace
from typing import Any

import ckan.model as model
from ckan import plugins
from ckan.common import config
from ckan.common import _, config
from ckan.lib.plugins import DefaultTranslation
from ckan.plugins import toolkit

Expand All @@ -24,6 +26,7 @@ class FeedbackPlugin(plugins.SingletonPlugin, DefaultTranslation):
plugins.implements(plugins.IBlueprint)
plugins.implements(plugins.ITemplateHelpers)
plugins.implements(plugins.ITranslation)
plugins.implements(plugins.IResourceController, inherit=True)

# IConfigurer

Expand Down Expand Up @@ -267,3 +270,32 @@ def get_helpers(self):
'get_package_rating': resource_summary_service.get_package_rating,
'get_organization': management_comments_service.get_organization,
}

# IResourceController

def before_resource_show(self, resource_dict: dict[str, Any]) -> dict[str, Any]:
owner_org = model.Package.get(resource_dict['package_id']).owner_org
resource_id = resource_dict['id']
if self.is_enabled_downloads_org(owner_org):
resource_dict[_('Downloads')] = (
download_summary_service.get_resource_downloads(resource_id)
)

if self.is_enabled_utilizations_org(owner_org):
resource_dict[_('Utilizations')] = (
utilization_summary_service.get_resource_utilizations(resource_id)
)
resource_dict[_('Issue Resolutions')] = (
utilization_summary_service.get_resource_issue_resolutions(resource_id)
)

if self.is_enabled_resources_org(owner_org):
resource_dict[_('Comments')] = (
resource_summary_service.get_resource_comments(resource_id)
)
if self.is_enabled_rating_org(owner_org):
resource_dict[_('Rating')] = round(
resource_summary_service.get_resource_rating(resource_id), 1
)

return resource_dict
71 changes: 0 additions & 71 deletions ckanext/feedback/templates/package/resource_read.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,74 +78,3 @@
<p class="text-muted break-word">{{ _('URL:') }} {{ res.url }}</p>
{% endif %}
{% endblock %}

{% block resource_additional_information_inner %}
<div class="module-content">
<h2>{{ _('Additional Information') }}</h2>
<table class="table table-striped table-bordered table-condensed" data-module="table-toggle-more">
<thead>
<tr>
<th scope="col">{{ _('Field') }}</th>
<th scope="col">{{ _('Value') }}</th>
</tr>
</thead>
<tbody>
{% if h.is_enabled_downloads_org(pkg.owner_org) %}
<tr>
<th scope="row">{{ _('Downloads') }}</th>
<td>{{ h.get_resource_downloads(res.id) }}</td>
</tr>
{% endif %}
{% if h.is_enabled_utilizations_org(pkg.owner_org) %}
<tr>
<th scope="row">{{ _('Utilizations') }}</th>
<td><a href="{{ h.url_for('utilization.search', id=resource.id, disable_keyword=true) }}">{{ h.get_resource_utilizations(resource.id) }}</a></td>
</tr>
{% endif %}
{% if h.is_enabled_resources_org(pkg.owner_org) %}
<tr>
<th scope="row">{{ _('Comments') }}</th>
<td><a href="{{ h.url_for('resource_comment.comment', resource_id=res.id) }}">{{ h.get_resource_comments(resource.id) }}</a></td>
</tr>
{% if h.is_enabled_rating_org(pkg.owner_org) %}
<tr>
<th scope="row">{{ _('Rating') }}</th>
<td>{{ h.get_resource_rating(resource.id)|round(1) }}</td>
</tr>
{% endif %}
{% endif %}
{% if h.is_enabled_utilizations_org(pkg.owner_org) %}
<tr>
<th scope="row">{{ _('Issue Resolutions') }}</th>
<td>{{ h.get_resource_issue_resolutions(res.id) }}</td>
</tr>
{% endif %}
<tr>
<th scope="row">{{ _('Data last updated') }}</th>
<td>{{ h.render_datetime(res.last_modified) or h.render_datetime(res.created) or _('unknown') }}</td>
</tr>
<tr>
<th scope="row">{{ _('Metadata last updated') }}</th>
<td>{{ h.render_datetime(res.metadata_modified) or h.render_datetime(res.created) or _('unknown') }}</td>
</tr>
<tr>
<th scope="row">{{ _('Created') }}</th>
<td>{{ h.render_datetime(res.created) or _('unknown') }}</td>
</tr>
<tr>
<th scope="row">{{ _('Format') }}</th>
<td>{{ res.format or res.mimetype_inner or res.mimetype or _('unknown') }}</td>
</tr>
<tr>
<th scope="row">{{ _('License') }}</th>
<td>{% snippet "snippets/license.html", pkg_dict=pkg, text_only=True %}</td>
</tr>
{% for key, value in h.format_resource_items(res.items()) %}
{% if key not in ('created', 'metadata modified', 'last modified', 'format') %}
<tr class="toggle-more"><th scope="row">{{ key | capitalize }}</th><td>{{ value }}</td></tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

0 comments on commit eabbaa3

Please sign in to comment.