Skip to content

Commit

Permalink
Merge a83f972 into 295a6dc
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Oct 1, 2019
2 parents 295a6dc + a83f972 commit 73b022c
Show file tree
Hide file tree
Showing 32 changed files with 2,366 additions and 1,345 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,7 @@ addons:
apt:
packages:
- expect-dev # provides unbuffer utility
- python-magic

language: python

Expand Down
87 changes: 75 additions & 12 deletions attachment_preview/README.rst
@@ -1,46 +1,109 @@
===================
Preview attachments
===================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
:target: https://github.com/OCA/knowledge/tree/10.0/attachment_preview
:alt: OCA/knowledge
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/knowledge-10-0/knowledge-10-0-attachment_preview
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/118/10.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon allows to preview attachments supported by http://viewerjs.org.

Currently, that's most Libreoffice files and PDFs.

.. image:: /attachment_preview/static/description/screenshot-split.png
:alt: Screenshot of split form view
:width: 100%

**Table of contents**

.. contents::
:local:

Installation
============

For filetype recognition, you'll get the best results by installing
``python-magic``::
``python-magic``:

sudo apt-get install python-magic

Usage
=====

The module adds a little print preview icon right of download links for
attachments or binary fields.
attachments or binary fields. When a preview is opened from the attachments
menu it's shown next to the form view. From this screen you can navigate
through the attachments using the arrow buttons. Using the pop-out button
next to the navigational buttons you can open the preview in a separate window.

.. image:: /attachment_preview/static/description/screenshot-paginator.png
:alt: Screenshot navigator

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_preview%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Addon icon
----------
Authors
~~~~~~~

* courtesy of http://commons.wikimedia.org/wiki/Crystal_Clear
* Therp BV
* Onestein

Contributors
------------
~~~~~~~~~~~~

* Holger Brunn <hbrunn@therp.nl>
* Dennis Sluijk <d.sluijk@onestein.nl>

Other credits
~~~~~~~~~~~~~

Maintainer
Addon icon
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
* courtesy of http://commons.wikimedia.org/wiki/Crystal_Clear

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/10.0/attachment_preview>`_ project on GitHub.

To contribute to this module, please visit http://odoo-community.org.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
25 changes: 4 additions & 21 deletions attachment_preview/__init__.py
@@ -1,21 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model
# Copyright 2014 Therp BV (<http://therp.nl>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
43 changes: 10 additions & 33 deletions attachment_preview/__manifest__.py
@@ -1,46 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# Copyright 2014 Therp BV (<http://therp.nl>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Preview attachments",
"version": "8.0.1.1.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"version": "10.0.1.3.0",
"author": "Therp BV,"
"Onestein,"
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"complexity": "normal",
'summary': 'Preview attachments supported by Viewer.js',
"summary": 'Preview attachments supported by Viewer.js',
"category": "Knowledge Management",
"depends": [
'web',
],
"data": [
"view/attachment_preview.xml",
"templates/assets.xml",
],
"qweb": [
'static/src/xml/attachment_preview.xml',
],
"test": [
],
"auto_install": False,
'installable': False,
"application": False,
"external_dependencies": {
'python': [],
},
"installable": True,
}
21 changes: 0 additions & 21 deletions attachment_preview/model/__init__.py

This file was deleted.

68 changes: 0 additions & 68 deletions attachment_preview/model/ir_attachment.py

This file was deleted.

4 changes: 4 additions & 0 deletions attachment_preview/models/__init__.py
@@ -0,0 +1,4 @@
# Copyright 2014 Therp BV (<http://therp.nl>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import ir_attachment
77 changes: 77 additions & 0 deletions attachment_preview/models/ir_attachment.py
@@ -0,0 +1,77 @@
# Copyright 2014 Therp BV (<http://therp.nl>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import collections
import logging
import mimetypes
import os.path
import base64

from odoo import models, api

_logger = logging.getLogger(__name__)


class IrAttachment(models.Model):
_inherit = 'ir.attachment'

@api.model
def get_binary_extension(self, model, ids, binary_field,
filename_field=None):
result = {}
ids_to_browse = ids if isinstance(ids, collections.Iterable) else [ids]

# First pass: load fields in bin_size mode to avoid loading big files
# unnecessarily.
if filename_field:
for this in self.env[model].with_context(
bin_size=True).browse(ids_to_browse):
extension = ''
if this[filename_field]:
filename, extension = os.path.splitext(
this[filename_field])
if this[binary_field] and extension:
result[this.id] = extension
_logger.debug('Got extension %s from filename %s',
extension, this[filename_field])
# Second pass for all attachments which have to be loaded fully
# to get the extension from the content
ids_to_browse = [_id for _id in ids_to_browse if _id not in result]
for this in self.env[model].with_context(
bin_size=True).browse(ids_to_browse):
if not this[binary_field]:
result[this.id] = False
continue
try:
import magic
ms = magic.open(
hasattr(magic, 'MAGIC_MIME_TYPE') and
magic.MAGIC_MIME_TYPE or magic.MAGIC_MIME)
ms.load()
if model == self._name and binary_field == 'datas'\
and this.store_fname:
mimetype = ms.file(
this._full_path(this.store_fname))
_logger.debug('Magic determined mimetype %s from file %s',
mimetype, this.store_fname)
else:
mimetype = ms.buffer(
base64.b64decode(this[binary_field]))
_logger.debug('Magic determined mimetype %s from buffer',
mimetype)
except ImportError:
(mimetype, encoding) = mimetypes.guess_type(
'data:;base64,' + this[binary_field], strict=False)
_logger.debug('Mimetypes guessed type %s from buffer',
mimetype)
extension = mimetypes.guess_extension(
mimetype.split(';')[0], strict=False)
result[this.id] = extension
for _id in result:
result[_id] = (result[_id] or '').lstrip('.').lower()
return result if isinstance(ids, collections.Iterable) else result[ids]

@api.model
def get_attachment_extension(self, ids):
return self.get_binary_extension(
self._name, ids, 'datas', 'datas_fname')
2 changes: 2 additions & 0 deletions attachment_preview/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Holger Brunn <hbrunn@therp.nl>
* Dennis Sluijk <d.sluijk@onestein.nl>
4 changes: 4 additions & 0 deletions attachment_preview/readme/CREDITS.rst
@@ -0,0 +1,4 @@
Addon icon
----------

* courtesy of http://commons.wikimedia.org/wiki/Crystal_Clear

0 comments on commit 73b022c

Please sign in to comment.