Skip to content

Commit

Permalink
Remove old resource preview system
Browse files Browse the repository at this point in the history
Before the current resource views (CKAN 2.3) there was another
implementation for a more rudimentary system, which was still supported.
This removes this long unused code, simplyfing a bit the resource read
template, removing unused templates and helpers.
  • Loading branch information
amercader committed Jun 30, 2021
1 parent 6f3e6a2 commit 97d3d00
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 163 deletions.
30 changes: 0 additions & 30 deletions ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2349,36 +2349,6 @@ def format_resource_items(items):
return sorted(output, key=lambda x: x[0])


@core_helper
def resource_preview(resource, package):
'''
Returns a rendered snippet for a embedded resource preview.
Depending on the type, different previews are loaded.
This could be an img tag where the image is loaded directly or an iframe
that embeds a web page or a recline preview.
'''

if not resource['url']:
return False

datapreview.res_format(resource)
directly = False
data_dict = {'resource': resource, 'package': package}

if datapreview.get_preview_plugin(data_dict, return_first=True):
url = url_for('{}_resource.datapreview'.format(package['type']),
resource_id=resource['id'], id=package['id'],
qualified=True)
else:
return False

return snippet("dataviewer/snippets/data_preview.html",
embed=directly,
resource_url=url,
raw_resource_url=resource.get('url'))


@core_helper
def get_allowed_view_types(resource, package):
data_dict = {'resource': resource, 'package': package}
Expand Down
15 changes: 0 additions & 15 deletions ckan/templates/dataviewer/base.html

This file was deleted.

26 changes: 0 additions & 26 deletions ckan/templates/dataviewer/snippets/data_preview.html

This file was deleted.

16 changes: 0 additions & 16 deletions ckan/templates/dataviewer/snippets/no_preview.html

This file was deleted.

10 changes: 1 addition & 9 deletions ckan/templates/package/resource_read.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,18 @@ <h3>{{ _('Dataset description:') }}</h3>
{% block data_preview %}
{% block resource_view %}
{% block resource_view_nav %}
{% set resource_preview = h.resource_preview(resource, package) %}
{% snippet "package/snippets/resource_views_list.html",
views=resource_views,
pkg=pkg,
is_edit=false,
view_id=current_resource_view['id'],
resource_preview=resource_preview,
resource=resource,
extra_class="nav-tabs nav-tabs-plain"
%}
{% endblock %}
{% block resource_view_content %}
<div class="resource-view">
{% set resource_preview = h.resource_preview(resource, package) %}
{% set views_created = res.has_views or resource_preview %}
{% if views_created %}
{% if resource_preview and not current_resource_view %}
{{ h.resource_preview(resource, package) }}
{% else %}
{% if resource_views %}
{% for resource_view in resource_views %}
{% if resource_view == current_resource_view %}
{% snippet 'package/snippets/resource_view.html',
Expand All @@ -133,7 +126,6 @@ <h3>{{ _('Dataset description:') }}</h3>
%}
{% endif %}
{% endfor %}
{% endif %}
{% else %}
{# Views not created #}
<div class="data-viewer-info">
Expand Down
12 changes: 1 addition & 11 deletions ckan/templates/package/snippets/resource_views_list.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{% set views_created = views or resource_preview %}
{% if views_created %}
{% if views %}
<ul class="nav {{ extra_class }}" {{ extra_attributes }}>
{% if resource_preview %}
<li{% if not view_id %} class="active"{% endif %}>
<a href="{{ h.url_for(pkg.type ~ '_resource.read', id=pkg.name, resource_id=resource.id) }}" >
<i class="fa icon fa-eye-open"></i>
{{ _("Resource Preview") }}
</a>
</li>
{% endif %}

{% set current_filters = request.args.get('filters') %}
{% for view in views %}
{% set is_selected = true if view_id == view.id else false %}
Expand Down
48 changes: 0 additions & 48 deletions ckan/tests/legacy/ckantestplugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,51 +156,3 @@ def after_show(self, context, data_dict):

def update_facet_titles(self, facet_titles):
return facet_titles


class MockResourcePreviewExtension(mock_plugin.MockSingletonPlugin):
p.implements(p.IResourcePreview)

def __init__(self, *args, **kw):
self.calls = defaultdict(int)

def setup_template_variables(self, context, data_dict):
self.calls["setup_template_variables"] += 1

def can_preview(self, data_dict):
assert isinstance(data_dict["resource"], dict)
assert isinstance(data_dict["package"], dict)
assert "on_same_domain" in data_dict["resource"]

self.calls["can_preview"] += 1
return data_dict["resource"]["format"].lower() == "mock"

def preview_template(self, context, data_dict):
assert isinstance(data_dict["resource"], dict)
assert isinstance(data_dict["package"], dict)

self.calls["preview_templates"] += 1
return "tests/mock_resource_preview_template.html"


class JsonMockResourcePreviewExtension(mock_plugin.MockSingletonPlugin):
p.implements(p.IResourcePreview)

def __init__(self, *args, **kw):
self.calls = defaultdict(int)

def setup_template_variables(self, context, data_dict):
self.calls["setup_template_variables"] += 1

def can_preview(self, data_dict):
self.calls["can_preview"] += 1
return data_dict["resource"]["format"].lower() == "json"

def preview_template(self, context, data_dict):
self.calls["preview_templates"] += 1
return "tests/mock_json_resource_preview_template.html"


# importing this file loads all these extensions by default
# so clean up the extensions
# p.plugins_update()
5 changes: 4 additions & 1 deletion ckanext/textview/theme/templates/text_view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'dataviewer/base.html' %}
{% extends "base.html" %}

{% block subtitle %}{% endblock %}

Expand All @@ -19,6 +19,9 @@
</script>
{% endblock %}

{% block styles %}{% endblock %}
{% block custom_styles %}{% endblock %}

{% asset 'ckanext-textview/main' %}
{% endblock %}

7 changes: 0 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,9 @@
'audio_view = ckanext.audioview.plugin:AudioView',
'video_view = ckanext.videoview.plugin:VideoView',
'webpage_view = ckanext.webpageview.plugin:WebPageView',
# FIXME: Remove deprecated resource previews below. You should use the
# versions as *_view instead.
'text_preview = ckanext.textview.plugin:TextView',
'recline_preview = ckanext.reclineview.plugin:ReclineView',
'recline_grid = ckanext.reclineview.plugin:ReclineGridView',
'recline_graph = ckanext.reclineview.plugin:ReclineGraphView',
'recline_map = ckanext.reclineview.plugin:ReclineMapView',
# End of deprecated previews
'example_itemplatehelpers = ckanext.example_itemplatehelpers.plugin:ExampleITemplateHelpersPlugin',
'example_idatasetform = ckanext.example_idatasetform.plugin:ExampleIDatasetFormPlugin',
'example_idatasetform_v1 = ckanext.example_idatasetform.plugin_v1:ExampleIDatasetFormPlugin',
Expand Down Expand Up @@ -171,8 +166,6 @@
'auth_plugin = tests.legacy.ckantestplugins:AuthPlugin',
'test_group_plugin = tests.legacy.ckantestplugins:MockGroupControllerPlugin',
'test_package_controller_plugin = tests.legacy.ckantestplugins:MockPackageControllerPlugin',
'test_resource_preview = tests.legacy.ckantestplugins:MockResourcePreviewExtension',
'test_json_resource_preview = tests.legacy.ckantestplugins:JsonMockResourcePreviewExtension',
'sample_datastore_plugin = ckanext.datastore.tests.sample_datastore_plugin:SampleDataStorePlugin',
'example_datastore_deleted_with_count_plugin = ckanext.datastore.tests.test_chained_action:ExampleDataStoreDeletedWithCountPlugin',
'example_data_store_search_sql_plugin = ckanext.datastore.tests.test_chained_auth_functions:ExampleDataStoreSearchSQLPlugin',
Expand Down

0 comments on commit 97d3d00

Please sign in to comment.