Browse Source

Update Version

pull/5/head
Mathias Markl 8 years ago
parent
commit
76798c6584
  1. 2
      muk_web_preview/__manifest__.py
  2. 13
      muk_web_preview/static/lib/ViewerJS/index.html
  3. 10
      muk_web_preview_msoffice/README.md
  4. 12
      muk_web_preview_msoffice/__manifest__.py
  5. 66
      muk_web_preview_msoffice/controllers/main.py
  6. 2
      muk_web_preview_msoffice/static/src/js/preview_generator.js
  7. 37
      muk_web_preview_msoffice/static/src/js/preview_handler.js

2
muk_web_preview/__manifest__.py

@ -29,7 +29,7 @@
- Portable Document Format (.pdf)
- Open Document (.odt, .odp, .ods, .otp)
""",
"version": "10.0.1.0.2",
"version": "10.0.1.0.3",
"category": "Extra Tools",
"license": "AGPL-3",
"website": "http://www.mukit.at",

13
muk_web_preview/static/lib/ViewerJS/index.html

@ -72,11 +72,20 @@ c;a?(e.title||(e.title=a.replace(/^.*[\\\/]/,"")),e.documentUrl=a,b(a,function(b
</script>
<script type="text/javascript">
var original_Viewer = Viewer;
Viewer = function(plugin, parameters) {
var matches = (/&(filename=([^&]+)|title=([^&]+)|)&/).exec(window.location.hash);
if(matches && matches.length > 1) {
parameters.title = decodeURIComponent(matches[2]);
console.log(matches);
parameters.title = decodeURIComponent(matches[2] || matches[3]);
} else {
matches = (/&(filename=([^&]+)|title=([^&]+)|)/).exec(window.location.hash);
console.log(matches);
if(matches && matches.length > 1) {
parameters.title = decodeURIComponent(matches[2] || matches[3]);
} else {
parameters.title = "";
}
}
return original_Viewer(plugin, parameters);
}

10
muk_web_preview_msoffice/README.md

@ -1,7 +1,7 @@
# MuK Preview Video
# MuK Preview MS Office
Extendes the Preview Dialog to support videos. Currently the following video extensions are supported:
Extendes the Preview Dialog to support MS Office files. Currently the following file extensions are supported:
* WebM (*.webm, video/webm)
* Ogg Theora Vorbis (*.ogg, video/ogg)
* MP4 (*.mp4, video/mp4)
* Word (*.doc | *.docx, application/msword)
* Excel (*.xls | *.xlsx, application/msexcel)
* PowerPoint (*.ppt | *.pptx, application/mspowerpoint)

12
muk_web_preview_msoffice/__manifest__.py

@ -23,13 +23,13 @@
"name": "MuK Preview MS Office",
"summary": """MS Office Preview""",
"description": """
Extendes the Preview Dialog to support videos.
Currently the following video extensions are supported:
- WebM (*.webm, video/webm)
- Ogg Theora Vorbis (*.ogg, video/ogg)
- MP4 (*.mp4, video/mp4)
Extendes the Preview Dialog to support MS Office files.
Currently the following file extensions are supported:
- Word (*.doc | *.docx, application/msword)
- Excel (*.xls | *.xlsx, application/msexcel)
- PowerPoint (*.ppt | *.pptx, application/mspowerpoint)
""",
"version": "10.0.1.0.0",
"version": "10.0.1.0.1",
"category": "Extra Tools",
"license": "AGPL-3",
"website": "http://www.mukit.at",

66
muk_web_preview_msoffice/controllers/main.py

@ -22,6 +22,7 @@
import os
import sys
import json
import uuid
import base64
import urllib
import urllib2
@ -64,13 +65,37 @@ class Main(http.Controller):
@http.route('/web/preview/converter/msoffice', auth="user", type='http')
def convert_msoffice(self, url, filename=None, force_compute=False, **kw):
try:
pdf = pdf_cache[url] if pdf_cache and not force_compute else None
except (KeyError, NameError):
pdf = None
if not pdf:
response = pdf_cache[url] if pdf_cache and not force_compute else None
except KeyError:
response = None
if not response:
return self._get_response(url, filename)
return pdf
def _get_response(self, url, filename):
if not bool(urlparse.urlparse(url).netloc):
method, params = self._get_route(url)
response = method(**params)
if not response.status_code == 200:
return self._make_error_response(response.status_code,response.description if hasattr(response, 'description') else _("Unknown Error"))
else:
content_type = response.headers['content-type']
data = response.data
else:
try:
response = requests.get(url)
content_type = response.headers['content-type']
data = response.content
except requests.exceptions.RequestException as exception:
return self._make_error_response(exception.response.status_code, exception.response.reason or _("Unknown Error"))
try:
return self._make_pdf_response(pdfconv.converter.convert_binary2pdf(data, content_type, filename, format='binary'), filename or uuid.uuid4())
except KeyError:
return werkzeug.exceptions.UnsupportedMediaType(_("The file couldn't be converted. Unsupported mine type."))
except (ImportError, IOError, WindowsError) as error:
_logger.error(error)
return werkzeug.exceptions.InternalServerError(_("An error occurred during the process. Please contact your system administrator."))
def _get_route(self, url):
url_parts = url.split('?')
path = url_parts[0]
@ -93,35 +118,4 @@ class Main(http.Controller):
headers = [('Content-Type', 'application/pdf'),
('Content-Disposition', 'attachment;filename={};'.format(filename)),
('Content-Length', len(file))]
return request.make_response(file, headers)
def _get_response(self, url, filename):
if not bool(urlparse.urlparse(url).netloc):
method, params = self._get_route(url)
response = method(**params)
if not response.status_code == 200:
return self._make_error_response(response.status_code,response.description if hasattr(response, 'description') else _("Unknown Error"))
else:
content_type = response.headers['content-type']
data = response.data
else:
if requests:
try:
response = requests.get(url)
content_type = response.headers['content-type']
data = response.content
except requests.exceptions.RequestException as exception:
return self._make_error_response(exception.response.status_code, exception.response.reason or _("Unknown Error"))
else:
_logger.error("Python library requests is missing.")
return werkzeug.exceptions.InternalServerError(_("To convert files the Python library requests needs to be installed." +
"Please contact your system administrator."))
try:
return werkzeug.exceptions.NotImplemented()
except KeyError:
return werkzeug.exceptions.UnsupportedMediaType(_("The file couldn't be converted. Unsupported mine type."))
return request.make_response(file, headers)

2
muk_web_preview_msoffice/static/src/js/preview_generator.js

@ -33,6 +33,8 @@ PreviewGenerator.include({
this._super(widget, additional_handler);
this.handler = _.extend(this.handler, {
"ExcelHandler": new PreviewHandler.ExcelHandler(widget),
"WordHandler": new PreviewHandler.WordHandler(widget),
"PowerPointHandler": new PreviewHandler.PowerPointHandler(widget),
});
},
});

37
muk_web_preview_msoffice/static/src/js/preview_handler.js

@ -27,12 +27,45 @@ var PreviewHandler = require('muk_preview.PreviewHandler');
var QWeb = core.qweb;
var _t = core._t;
var WordHandler = PreviewHandler.PDFHandler.extend({
checkExtension: function(extension) {
return ['.doc', '.docx', '.docm', 'doc', 'docx', 'docm'].includes(extension);
},
checkType: function(mimetype) {
return ['application/msword', 'application/ms-word', 'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'].includes(mimetype);
},
createHtml: function(url, mimetype, extension, title) {
return this._super('/web/preview/converter/msoffice?' + $.param({
'url': url,
'title': title,
}));
},
});
var PowerPointHandler = PreviewHandler.PDFHandler.extend({
checkExtension: function(extension) {
return ['.ppt', '.pptx', '.pptm', 'ppt', 'pptx', 'pptm'].includes(extension);
},
checkType: function(mimetype) {
return ['application/vnd.mspowerpoint', 'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12'].includes(mimetype);
},
createHtml: function(url, mimetype, extension, title) {
return this._super('/web/preview/converter/msoffice?' + $.param({
'url': url,
'title': title,
}));
},
});
var ExcelHandler = PreviewHandler.BaseHandler.extend({
checkExtension: function(extension) {
return ['.xls', '.xlsx', '.xlsm', '.xlsb', 'xls', 'xlsx', 'xlsm', 'xlsb'].includes(extension);
},
checkType: function(mimetype) {
return ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
return ['application/vnd.ms-excel', 'application/vnd.msexcel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'application/vnd.ms-excel.sheet.macroEnabled.12'].includes(mimetype);
},
createHtml: function(url, mimetype, extension, title) {
@ -103,6 +136,8 @@ var ExcelHandler = PreviewHandler.BaseHandler.extend({
return {
ExcelHandler: ExcelHandler,
WordHandler: WordHandler,
PowerPointHandler: PowerPointHandler,
}
});
Loading…
Cancel
Save