From dcb042671c2056e547b9e30ac013143f3e8ac779 Mon Sep 17 00:00:00 2001 From: psbothra Date: Wed, 25 Apr 2018 17:09:23 +0530 Subject: [PATCH 1/4] Added the text for private datasets resource and hide the preview --- ckanext/officedocs/plugin.py | 4 +++- ckanext/officedocs/templates/officedocs/preview.html | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ckanext/officedocs/plugin.py b/ckanext/officedocs/plugin.py index e29dfab..685b3bb 100644 --- a/ckanext/officedocs/plugin.py +++ b/ckanext/officedocs/plugin.py @@ -24,8 +24,10 @@ def info(self): def setup_template_variables(self, context, data_dict): from urllib import quote_plus url = quote_plus(data_dict["resource"]["url"]) + private_visibility = data_dict["package"]["private"] return { - "resource_url": url + "resource_url": url, + "visibility": private_visibility } def can_view(self, data_dict): diff --git a/ckanext/officedocs/templates/officedocs/preview.html b/ckanext/officedocs/templates/officedocs/preview.html index b0ec6a7..e5ef481 100644 --- a/ckanext/officedocs/templates/officedocs/preview.html +++ b/ckanext/officedocs/templates/officedocs/preview.html @@ -1,3 +1,6 @@ +{% if visibility %} +
This resource view will render once the dataset is made public. Microsoft Office preview is unable to access and display private resources.
+{% else %} +{% endif %} \ No newline at end of file From cacb1a0020c0e13b9b7ff509db3859de3441ef70 Mon Sep 17 00:00:00 2001 From: psbothra Date: Wed, 2 May 2018 12:15:38 +0530 Subject: [PATCH 2/4] Renaming the variable --- ckanext/officedocs/plugin.py | 4 ++-- ckanext/officedocs/templates/officedocs/preview.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ckanext/officedocs/plugin.py b/ckanext/officedocs/plugin.py index 685b3bb..b61c2fb 100644 --- a/ckanext/officedocs/plugin.py +++ b/ckanext/officedocs/plugin.py @@ -24,10 +24,10 @@ def info(self): def setup_template_variables(self, context, data_dict): from urllib import quote_plus url = quote_plus(data_dict["resource"]["url"]) - private_visibility = data_dict["package"]["private"] + private_package = data_dict["package"]["private"] return { "resource_url": url, - "visibility": private_visibility + "private_package": private_package } def can_view(self, data_dict): diff --git a/ckanext/officedocs/templates/officedocs/preview.html b/ckanext/officedocs/templates/officedocs/preview.html index e5ef481..599bd8e 100644 --- a/ckanext/officedocs/templates/officedocs/preview.html +++ b/ckanext/officedocs/templates/officedocs/preview.html @@ -1,4 +1,4 @@ -{% if visibility %} +{% if private_package %}
This resource view will render once the dataset is made public. Microsoft Office preview is unable to access and display private resources.
{% else %} From 56baa016e9b49679a8eb545b2b5ee9809cad5cbc Mon Sep 17 00:00:00 2001 From: psbothra Date: Thu, 3 May 2018 11:22:17 +0530 Subject: [PATCH 3/4] aligned the message in center --- ckanext/officedocs/templates/officedocs/preview.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/officedocs/templates/officedocs/preview.html b/ckanext/officedocs/templates/officedocs/preview.html index 599bd8e..c422bc1 100644 --- a/ckanext/officedocs/templates/officedocs/preview.html +++ b/ckanext/officedocs/templates/officedocs/preview.html @@ -1,5 +1,5 @@ {% if private_package %} -
This resource view will render once the dataset is made public. Microsoft Office preview is unable to access and display private resources.
+
This resource view will render once the dataset is made public. Microsoft Office preview is unable to access and display private resources.
{% else %} From a68736e41bc922a6ce150d2a2bc3b9c88d0302a1 Mon Sep 17 00:00:00 2001 From: Jay Guo Date: Thu, 8 Jul 2021 11:21:25 -0400 Subject: [PATCH 4/4] [OD-1692] Add python 3 support (#2) * Clarify how to get office doc default views. * Added link to MS Online Doc Viewer site * Ooops... use RestructuredText markup, not Markdown * Add python 3 support and tests Co-authored-by: Ross Jones Co-authored-by: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> --- .gitignore | 4 +++- README.rst | 12 +++++++++--- ckanext/officedocs/plugin.py | 10 +++++----- ckanext/officedocs/tests/test_plugin.py | 5 ----- ckanext/officedocs/tests/test_view.py | 24 ++++++++++++++++++++++++ test.ini | 1 + 6 files changed, 42 insertions(+), 14 deletions(-) delete mode 100644 ckanext/officedocs/tests/test_plugin.py create mode 100644 ckanext/officedocs/tests/test_view.py diff --git a/.gitignore b/.gitignore index e9876d1..467fe2e 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,6 @@ nosetests.xml coverage.xml # Sphinx documentation -docs/_build/ \ No newline at end of file +docs/_build/ + +.DS_Store diff --git a/README.rst b/README.rst index 2f86e07..255d8c5 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ ckanext-officedocs ============= -This plugin provides the option of using the Microsoft Office viewer for +This plugin provides the option of using the `Microsoft Online Doc Viewer `_ for previewing both MS Office and OpenOffice documents as an IResourceView ------------ @@ -31,11 +31,17 @@ To install ckanext-officedocs: cd ckanext-officedocs python setup.py install -3. Add ``officedocs_view`` to the ``ckan.plugins`` setting in your CKAN +4. Add ``officedocs_view`` to the ``ckan.plugins`` setting in your CKAN config file (by default the config file is located at ``/etc/ckan/default/production.ini``). + +5. If you wish for views to be created automatically for you, then you should + add ``officedocs_view`` to the end of the ``ckan.views.default_views`` option in your + config file. -4. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:: + ckan.views.default_views = ... officedocs_view + +6. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:: sudo service apache2 reload diff --git a/ckanext/officedocs/plugin.py b/ckanext/officedocs/plugin.py index b61c2fb..a8d3e73 100644 --- a/ckanext/officedocs/plugin.py +++ b/ckanext/officedocs/plugin.py @@ -1,5 +1,6 @@ import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit +from six.moves.urllib.parse import quote_plus class OfficeDocsPlugin(plugins.SingletonPlugin): @@ -22,7 +23,6 @@ def info(self): } def setup_template_variables(self, context, data_dict): - from urllib import quote_plus url = quote_plus(data_dict["resource"]["url"]) private_package = data_dict["package"]["private"] return { @@ -34,10 +34,10 @@ def can_view(self, data_dict): supported_formats = [ "DOC", "DOCX", "XLS", "XLSX", "PPT", "PPTX", "PPS", "ODT", "ODS", "ODP" ] - try: - return data_dict['resource'].get('format', '').upper() in supported_formats - except: - return False + format_upper = data_dict['resource'].get('format', '').upper() + if format_upper in supported_formats: + return True + return False def view_template(self, context, data_dict): return "officedocs/preview.html" diff --git a/ckanext/officedocs/tests/test_plugin.py b/ckanext/officedocs/tests/test_plugin.py deleted file mode 100644 index 631778a..0000000 --- a/ckanext/officedocs/tests/test_plugin.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Tests for plugin.py.""" -import ckanext.gdoc.plugin as plugin - -def test_plugin(): - pass \ No newline at end of file diff --git a/ckanext/officedocs/tests/test_view.py b/ckanext/officedocs/tests/test_view.py new file mode 100644 index 0000000..09aab60 --- /dev/null +++ b/ckanext/officedocs/tests/test_view.py @@ -0,0 +1,24 @@ +import ckan.plugins as p +from ckan.tests import factories + +def test_view_on_resource_page(): + sysadmin = factories.Sysadmin() + dataset = factories.Dataset() + resource = factories.Resource( + package_id = dataset['id'], + url = 'http://link.to.some.data', + format = 'XLS' + ) + resource_view = factories.ResourceView( + resource_id = resource['id'], + title = 'Preview', + view_type = 'officedocs_view' + ) + + response = p.toolkit.get_action('resource_view_show')( + {'user': sysadmin.get('name')}, + {'id': resource_view.get('id')} + ) + + assert response.get('title') == 'Preview' + assert response.get('view_type') == 'officedocs_view' diff --git a/test.ini b/test.ini index c7c70e7..d64bd7f 100644 --- a/test.ini +++ b/test.ini @@ -13,6 +13,7 @@ use = config:../ckan/test-core.ini # Insert any custom config settings to be used when running your extension's # tests here. +ckan.plugins = officedocs_view # Logging configuration