Skip to content

Commit

Permalink
[OD-1692] Add python 3 support (#2)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Joel Natividad <[email protected]>
  • Loading branch information
3 people authored Jul 8, 2021
1 parent b017fc1 commit a68736e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ nosetests.xml
coverage.xml

# Sphinx documentation
docs/_build/
docs/_build/

.DS_Store
12 changes: 9 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://products.office.com/en/office-online/view-office-documents-online>`_ for
previewing both MS Office and OpenOffice documents as an IResourceView

------------
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions ckanext/officedocs/plugin.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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 {
Expand All @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions ckanext/officedocs/tests/test_plugin.py

This file was deleted.

24 changes: 24 additions & 0 deletions ckanext/officedocs/tests/test_view.py
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a68736e

Please sign in to comment.