From d8f45c5f8a7e570b995c52a830fd7e999e37f61d Mon Sep 17 00:00:00 2001 From: lian Date: Mon, 24 Aug 2015 15:32:04 +0800 Subject: [PATCH 1/2] use office web app to preview office document --- seahub/api2/urls.py | 6 ++++ seahub/templates/view_wopi_file.html | 52 ++++++++++++++++++++++++++++ seahub/views/file.py | 27 +++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 seahub/templates/view_wopi_file.html diff --git a/seahub/api2/urls.py b/seahub/api2/urls.py index a59551f855..d0a5fb978a 100644 --- a/seahub/api2/urls.py +++ b/seahub/api2/urls.py @@ -122,3 +122,9 @@ if HAS_OFFICE_CONVERTER: urlpatterns += patterns('', url(r'^office-convert/generate/repos/(?P[-0-9-a-f]{36})/$', OfficeGenerateView.as_view()), ) + +from seahub import settings +if getattr(settings, 'ENABLE_OFFICE_WEB_APP', False): + urlpatterns += patterns('', + (r'^wopi/', include('seahub_extra.wopi.urls')), + ) diff --git a/seahub/templates/view_wopi_file.html b/seahub/templates/view_wopi_file.html new file mode 100644 index 0000000000..7876a68be6 --- /dev/null +++ b/seahub/templates/view_wopi_file.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + +
+ + +
+ + + + + + + diff --git a/seahub/views/file.py b/seahub/views/file.py index d3beac346b..d456b63db1 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -74,6 +74,17 @@ if HAS_OFFICE_CONVERTER: import seahub.settings as settings from seahub.settings import FILE_ENCODING_LIST, FILE_PREVIEW_MAX_SIZE, \ FILE_ENCODING_TRY_LIST, USE_PDFJS, MEDIA_URL, SITE_ROOT + +try: + from seahub.settings import ENABLE_OFFICE_WEB_APP +except ImportError: + ENABLE_OFFICE_WEB_APP = False + +try: + from seahub.settings import OFFICE_WEB_APP_FILE_EXTENSION +except ImportError: + OFFICE_WEB_APP_FILE_EXTENSION = () + from seahub.views import is_registered_user, check_repo_access_permission, \ get_unencry_rw_repos_by_user, get_file_access_permission @@ -366,6 +377,22 @@ def _file_view(request, repo_id, path): if not user_perm: return render_permission_error(request, _(u'Unable to view file')) + # check if use wopi host page according to filetype + if ENABLE_OFFICE_WEB_APP: + if filetype in (DOCUMENT, SPREADSHEET, OPENDOCUMENT) or \ + fileext in OFFICE_WEB_APP_FILE_EXTENSION: + + try: + from seahub_extra.wopi.utils import get_wopi_dict + except ImportError: + wopi_dict = None + else: + wopi_dict = get_wopi_dict(username, repo_id, path) + + if wopi_dict: + return render_to_response('view_wopi_file.html', wopi_dict, + context_instance=RequestContext(request)) + # check if the user is the owner or not, for 'private share' if is_org_context(request): repo_owner = seafile_api.get_org_repo_owner(repo.id) From ebdd75a54703851ad38ee902fac105c5f3bf63a2 Mon Sep 17 00:00:00 2001 From: lian Date: Mon, 24 Aug 2015 17:29:03 +0800 Subject: [PATCH 2/2] update file ext check when use office web app --- seahub/views/file.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/seahub/views/file.py b/seahub/views/file.py index d456b63db1..3db77112df 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -378,20 +378,17 @@ def _file_view(request, repo_id, path): return render_permission_error(request, _(u'Unable to view file')) # check if use wopi host page according to filetype - if ENABLE_OFFICE_WEB_APP: - if filetype in (DOCUMENT, SPREADSHEET, OPENDOCUMENT) or \ - fileext in OFFICE_WEB_APP_FILE_EXTENSION: + if ENABLE_OFFICE_WEB_APP and fileext in OFFICE_WEB_APP_FILE_EXTENSION: + try: + from seahub_extra.wopi.utils import get_wopi_dict + except ImportError: + wopi_dict = None + else: + wopi_dict = get_wopi_dict(username, repo_id, path) - try: - from seahub_extra.wopi.utils import get_wopi_dict - except ImportError: - wopi_dict = None - else: - wopi_dict = get_wopi_dict(username, repo_id, path) - - if wopi_dict: - return render_to_response('view_wopi_file.html', wopi_dict, - context_instance=RequestContext(request)) + if wopi_dict: + return render_to_response('view_wopi_file.html', wopi_dict, + context_instance=RequestContext(request)) # check if the user is the owner or not, for 'private share' if is_org_context(request):