1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-18 23:18:27 +00:00

Merge pull request #764 from haiwen/wopi

use office web to preview office document
This commit is contained in:
Daniel Pan 2015-08-24 17:45:31 +08:00
commit 43e67758f6
3 changed files with 82 additions and 0 deletions

View File

@ -122,3 +122,9 @@ if HAS_OFFICE_CONVERTER:
urlpatterns += patterns('',
url(r'^office-convert/generate/repos/(?P<repo_id>[-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')),
)

View File

@ -0,0 +1,52 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Enable IE Standards mode -->
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
body {
margin: 0;
padding: 0;
overflow:hidden;
}
#office_frame {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
border: none;
display: block;
}
</style>
</head>
<body>
<form id="office_form" name="office_form" target="office_frame" action="{{action_url}}" method="post">
<input name="access_token" value="{{access_token}}" type="hidden"/>
<input name="access_token_ttl" value="{{access_token_ttl}}" type="hidden"/>
</form>
<span id="frameholder"></span>
<script type="text/javascript">
var frameholder = document.getElementById('frameholder');
var office_frame = document.createElement('iframe');
office_frame.name = 'office_frame';
office_frame.id ='office_frame';
frameholder.appendChild(office_frame);
document.getElementById('office_form').submit();
</script>
</body>
</html>

View File

@ -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,19 @@ 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 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)
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)