edgar 8 lat temu
commit
329e1470a8

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+import controllers

+ 16 - 0
__openerp__.py

@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+
+{
+    'name': 'Attachment browser',
+	'version': '1.0',
+	'depends': ['mail', 'knowledge'],
+    'author': 'Shurshilov Artem',
+    'category': 'Mail and Knowledge extension',
+    'description': """
+Attachment files are opened in browser
+==================================================================
+1. ir.attachment files from mail modul are opened in browser'
+2. ir.attachment files from knowledge modul are opened in browser
+    """,
+    'website': 'https://github.com/shurshilov',
+}

+ 3 - 0
controllers/__init__.py

@@ -0,0 +1,3 @@
+import main
+
+# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:

+ 65 - 0
controllers/main.py

@@ -0,0 +1,65 @@
+import base64
+import psycopg2
+import functools
+import openerp
+from openerp import SUPERUSER_ID
+from openerp import http
+from openerp.http import request
+from openerp.addons.web.controllers.main import content_disposition
+from openerp.addons.mail.controllers.main import MailController
+from openerp.addons.web.controllers.main import Binary
+import mimetypes
+import logging
+from openerp.http import request, serialize_exception as _serialize_exception
+_logger = logging.getLogger(__name__)
+
+def serialize_exception(f):
+    @functools.wraps(f)
+    def wrap(*args, **kwargs):
+        try:
+            return f(*args, **kwargs)
+        except Exception, e:
+            _logger.exception("An exception occured during an http request")
+            se = _serialize_exception(e)
+            error = {
+                'code': 200,
+                'message': "Odoo Server Error",
+                'data': se
+            }
+            return werkzeug.exceptions.InternalServerError(simplejson.dumps(error))
+    return wrap
+
+class MyMailController(MailController):
+    _cp_path = '/mail'
+
+    @http.route('/mail/download_attachment', type='http', auth='user')
+    def download_attachment(self, model, id, method, attachment_id, **kw):
+        result = super(MyMailController, self).download_attachment(model, id, method, attachment_id, **kw)
+        result.headers['Content-Disposition'] = result.headers['Content-Disposition'].replace('attachment', 'inline')
+        return result
+
+class MyBinary(Binary):  
+    @http.route('/web/binary/saveas', type='http', auth="public")
+    def saveas(self, model, field, id=None, filename_field=None, **kw):
+        Model = request.registry[model]
+        cr, uid, context = request.cr, request.uid, request.context
+        fields = [field]
+        if filename_field:
+            fields.append(filename_field)
+        if id:
+            res = Model.read(cr, uid, [int(id)], fields, context)[0]
+        else:
+            res = Model.default_get(cr, uid, fields, context)
+        filecontent = base64.b64decode(res.get(field) or '')
+        
+        if not filecontent:
+            return request.not_found()
+        else:
+            content_type = ""
+            filename = '%s_%s' % (model.replace('.', '_'), id)            
+            if filename_field:
+                filename = res.get(filename_field, '') or filename
+                content_type = mimetypes.guess_type(filename)
+            return request.make_response(filecontent,
+                headers=[('Content-Type',  content_type[0] or 'application/octet-stream'),
+                 ('Content-Disposition', content_disposition(filename).replace('attachment', 'inline'))])

BIN
static/description/1.png


BIN
static/description/2.png


BIN
static/description/3.png


BIN
static/description/4.png


BIN
static/description/5.png


+ 59 - 0
static/description/index.html

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<section class="oe_container oe_dark">
+    <div class="oe_row oe_spaced">
+        <h3 class="oe_slogan">When you click on your pdf document.</h3>
+        <div class="oe_span6">
+            <div class="oe_row_img oe_centered">
+                <img class="oe_picture oe_screenshot" src="3.png">
+            </div>
+        </div>
+    </div>
+</section>
+
+<section class="oe_container oe_dark">
+    <div class="oe_row oe_spaced">
+        <h3 class="oe_slogan">It open in new tab</h3>
+        <div class="oe_span6">
+            <div class="oe_row_img oe_centered">
+                <img class="oe_picture oe_screenshot" src="4.png">
+            </div>
+        </div>
+    </div>
+</section>
+<section class="oe_container">
+    <div class="oe_row oe_spaced">
+        <div class="oe_span12">
+            <h2 class="oe_slogan">Mail attachment ext</h2>
+            <h3 class="oe_slogan">When you click for example image</h3>
+        </div>
+        <div class="oe_span6">
+            <div class="oe_demo oe_picture oe_screenshot">
+                    <img src="1.png">
+            </div>
+        </div>
+    </div>
+</section>
+
+<section class="oe_container oe_dark">
+    <div class="oe_row oe_spaced">
+        <h3 class="oe_slogan">It don't download. It opened in new tab</h3>
+        <div class="oe_span6">
+            <div class="oe_row_img oe_centered">
+                <img class="oe_picture oe_screenshot" src="2.png">
+            </div>
+        </div>
+    </div>
+</section>
+
+<section class="oe_container oe_dark">
+    <div class="oe_row oe_spaced">
+        <h3 class="oe_slogan">Also in knowledge</h3>
+        <div class="oe_span6">
+            <div class="oe_row_img oe_centered">
+                <img class="oe_picture oe_screenshot" src="5.png">
+            </div>
+        </div>
+    </div>
+</section>
+
+