Skip to content

Commit

Permalink
Merge pull request #29 from tino097/wip
Browse files Browse the repository at this point in the history
Updating the extension
  • Loading branch information
jqnatividad authored Oct 23, 2024
2 parents 81ab7b5 + db7a6fb commit 02141ac
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ coverage.xml
# Sphinx documentation
docs/_build/
.vscode/
.DS_Store
4 changes: 3 additions & 1 deletion ckanext/officedocs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def info(self):

def setup_template_variables(self, context, data_dict):
url = quote_plus(data_dict["resource"]["url"])
private_package = data_dict["package"]["private"]
return {
"resource_url": url
"resource_url": url,
"private_package": private_package
}

def can_view(self, data_dict):
Expand Down
4 changes: 4 additions & 0 deletions ckanext/officedocs/templates/officedocs/preview.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% if private_package %}
<div style="text-align:center;">This resource view will render once the dataset is made public. Microsoft Office preview is unable to access and display private resources.</div>
{% else %}
<button id="fullscreeniframe" class="btn" style="position:absolute; right:5px; top:20px">Fullscreen</button>
<iframe id="cvframe" src="//view.officeapps.live.com/op/view.aspx?src={{resource_url}}" frameborder="0" allowfullscreen="" width="100%" height="400px"></iframe>
<script>
Expand Down Expand Up @@ -41,3 +44,4 @@
}, false);
})(this, this.document);
</script>
{% endif %}
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'

0 comments on commit 02141ac

Please sign in to comment.