Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into jguo144/2024-06-1…
Browse files Browse the repository at this point in the history
…1/merge-upstream
  • Loading branch information
jguo144 committed Jun 11, 2024
2 parents a68736e + 81ab7b5 commit 3b32ab5
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 190 deletions.
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ coverage.xml

# Sphinx documentation
docs/_build/

.DS_Store
.vscode/
.DS_Store
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include README.rst
recursive-include ckanext/officedocs *.html *.json *.js *.less *.css
include README.md
recursive-include ckanext/officedocs *.html *.json *.js *.less *.css
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ckanext-officedocs

This plugin provides the option of using the [Microsoft Office Web
Viewer](https://www.microsoft.com/en-us/microsoft-365/blog/2013/04/10/office-web-viewer-view-office-documents-in-a-browser/)
for previewing both MS Office and OpenOffice documents as an
IResourceView

## Supported formats

This plugin will attempt to preview the following formats

> \"DOC\", \"DOCX\", \"XLS\", \"XLSX\", \"XLSB\", \"PPT\", \"PPTX\", \"PPS\",
> \"PPSX\", \"ODT\", \"ODS\", \"ODP\"
## Installation

To install ckanext-officedocs:

1. Clone this repository into the place where you normally install
extensions, by default this will be /usr/lib/ckan/default/src/

2. Activate your CKAN virtual environment, for example:

. /usr/lib/ckan/default/bin/activate

3. Install the ckanext-officedocs Python package into your virtual
environment:

cd ckanext-officedocs
python setup.py install

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.

> ckan.views.default\_views = \... officedocs\_view
6. Restart CKAN. For example if you\'ve deployed CKAN with Apache on
Ubuntu:

sudo service apache2 reload

or if you\'re using `supervisor`:

sudo supervisorctl restart ckan-uwsgi:\*

## FAQ

Q: It doesn\'t work, my documents aren\'t previewing

A: For this extension to work, the documents to be previewed must be
accessible to the wider internet (i.e. the Dataset Package is PUBLIC, not PRIVATE),
and will only work if you use a hostname, and not just an IP address.
55 changes: 0 additions & 55 deletions README.rst

This file was deleted.

36 changes: 0 additions & 36 deletions bin/travis-build.bash

This file was deleted.

6 changes: 0 additions & 6 deletions bin/travis-run.sh

This file was deleted.

43 changes: 26 additions & 17 deletions ckanext/officedocs/plugin.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
import ckan.lib.helpers as h
import ckan.plugins as p
import ckan.plugins.toolkit as tk

from six.moves.urllib.parse import quote_plus


class OfficeDocsPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IResourceView)
class OfficeDocsPlugin(p.SingletonPlugin):
p.implements(p.IConfigurer)
p.implements(p.IResourceView)

def update_config(self, config_):
toolkit.add_template_directory(config_, 'templates')
toolkit.add_public_directory(config_, 'public')
toolkit.add_resource('fanstatic', 'officedocs')
tk.add_template_directory(config_, "templates")
tk.add_public_directory(config_, "public")
tk.add_resource("fanstatic", "officedocs")

def info(self):
return {
"name": "officedocs_view",
"title": toolkit._('Office Previewer'),
"default_title": toolkit._('Preview'),
"icon": "compass",
"always_available": True,
"title": tk._("Office Previewer"),
"default_title": tk._("Preview"),
"icon": "windows",
"always_available": False,
"iframed": False,
}

Expand All @@ -32,12 +34,19 @@ def setup_template_variables(self, context, data_dict):

def can_view(self, data_dict):
supported_formats = [
"DOC", "DOCX", "XLS", "XLSX", "PPT", "PPTX", "PPS", "ODT", "ODS", "ODP"
"DOC", "DOCX", "XLS",
"XLSX", "XLSB", "PPT", "PPTX",
"PPS", "PPSX", "ODT", "ODS", "ODP"
]
format_upper = data_dict['resource'].get('format', '').upper()
if format_upper in supported_formats:
return True
return False
try:
pkg_private = data_dict.get("package",{}).get("private", False)
if not pkg_private:
res = data_dict.get("resource",{}).get("format", "").upper()
return res in supported_formats
else:
return False
except Exception:
return False

def view_template(self, context, data_dict):
return "officedocs/preview.html"
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
six>=1.10.0 #pytest has requirement six>=1.10.0
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
here = path.abspath(path.dirname(__file__))

# Get the long description from the relevant file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

setup(
Expand All @@ -14,7 +14,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version='0.0.1',
version='1.1.0',

description='''A ResourceView that uses Microsoft's Doc preview''',
long_description=long_description,
Expand All @@ -23,8 +23,8 @@
url='https://github.com/rossjones/ckanext-officedocs',

# Author details
author='''Ross Jones''',
author_email='''[email protected]''',
author='''Ross Jones, Joel Natividad''',
author_email='''[email protected], [email protected]''',

# Choose your license
license='AGPL',
Expand All @@ -35,15 +35,15 @@
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
'Production/Stable :: 5',

# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.8',
],


Expand Down
50 changes: 0 additions & 50 deletions test.ini

This file was deleted.

0 comments on commit 3b32ab5

Please sign in to comment.