mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-20 10:16:45 -06:00
[ADD] document_choose_directory
This commit is contained in:
parent
cfb549d367
commit
7fad9182db
21
document_choose_directory/__init__.py
Normal file
21
document_choose_directory/__init__.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- 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
|
72
document_choose_directory/__openerp__.py
Normal file
72
document_choose_directory/__openerp__.py
Normal file
@ -0,0 +1,72 @@
|
||||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
"name": "Choose a document's directory during upload",
|
||||
"version": "1.0",
|
||||
"author": "Therp BV",
|
||||
"license": "AGPL-3",
|
||||
"complexity": "normal",
|
||||
"description": """
|
||||
Introduction
|
||||
============
|
||||
|
||||
This addons enables users to choose a directory while uploading a file. In
|
||||
combination with access permissions on directories, this can be used to
|
||||
restrict access on certain records' attachments or simply for a better
|
||||
overview.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
Create a static directory and choose the resource model you want to use this
|
||||
directory on. Assign groups to whom this directory should be accessible. When
|
||||
uploading a files, users can select one of the directories they have access to,
|
||||
or no directory which is the default setting.
|
||||
|
||||
Keep in mind that if a directory has a owner, it's only visible for this user,
|
||||
that's probably not what you want.
|
||||
""",
|
||||
"category": "Knowledge",
|
||||
"depends": [
|
||||
'document',
|
||||
'web',
|
||||
],
|
||||
"data": [
|
||||
"view/document_directory.xml",
|
||||
],
|
||||
"js": [
|
||||
'static/src/js/document_choose_directory.js',
|
||||
],
|
||||
"css": [
|
||||
'static/src/css/document_choose_directory.css',
|
||||
],
|
||||
"qweb": [
|
||||
'static/src/xml/document_choose_directory.xml',
|
||||
],
|
||||
"test": [
|
||||
],
|
||||
"auto_install": False,
|
||||
"installable": True,
|
||||
"application": False,
|
||||
"external_dependencies": {
|
||||
'python': [],
|
||||
},
|
||||
}
|
41
document_choose_directory/i18n/document_choose_directory.pot
Normal file
41
document_choose_directory/i18n/document_choose_directory.pot
Normal file
@ -0,0 +1,41 @@
|
||||
# Translation of OpenERP Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * document_choose_directory
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: OpenERP Server 7.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2014-07-30 11:27+0000\n"
|
||||
"PO-Revision-Date: 2014-07-30 11:27+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: document_choose_directory
|
||||
#. openerp-web
|
||||
#: code:addons/document_choose_directory/static/src/xml/document_choose_directory.xml:6
|
||||
#, python-format
|
||||
msgid "Choose directory"
|
||||
msgstr ""
|
||||
|
||||
#. module: document_choose_directory
|
||||
#: model:ir.model,name:document_choose_directory.model_document_directory
|
||||
msgid "Directory"
|
||||
msgstr ""
|
||||
|
||||
#. module: document_choose_directory
|
||||
#. openerp-web
|
||||
#: code:addons/document_choose_directory/static/src/js/document_choose_directory.js:64
|
||||
#, python-format
|
||||
msgid "No directory"
|
||||
msgstr ""
|
||||
|
||||
#. module: document_choose_directory
|
||||
#: model:ir.model,name:document_choose_directory.model_ir_attachment
|
||||
msgid "ir.attachment"
|
||||
msgstr ""
|
||||
|
35
document_choose_directory/i18n/nl.po
Normal file
35
document_choose_directory/i18n/nl.po
Normal file
@ -0,0 +1,35 @@
|
||||
# Translation of OpenERP Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * document_choose_directory
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: OpenERP Server 7.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2014-07-30 11:27+0000\n"
|
||||
"PO-Revision-Date: 2014-07-30 11:27+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: document_choose_directory
|
||||
#. openerp-web
|
||||
#: code:addons/document_choose_directory/static/src/xml/document_choose_directory.xml:6
|
||||
#, python-format
|
||||
msgid "Choose directory"
|
||||
msgstr "Kies map"
|
||||
|
||||
#. module: document_choose_directory
|
||||
#: model:ir.model,name:document_choose_directory.model_document_directory
|
||||
msgid "Directory"
|
||||
msgstr "Map"
|
||||
|
||||
#. module: document_choose_directory
|
||||
#. openerp-web
|
||||
#: code:addons/document_choose_directory/static/src/js/document_choose_directory.js:64
|
||||
#, python-format
|
||||
msgid "No directory"
|
||||
msgstr "Geen map"
|
22
document_choose_directory/model/__init__.py
Normal file
22
document_choose_directory/model/__init__.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- 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 document_directory
|
||||
from . import ir_attachment
|
74
document_choose_directory/model/document_directory.py
Normal file
74
document_choose_directory/model/document_directory.py
Normal file
@ -0,0 +1,74 @@
|
||||
# -*- 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 openerp.osv.orm import Model
|
||||
|
||||
|
||||
class DocumentDirectory(Model):
|
||||
_inherit = 'document.directory'
|
||||
|
||||
def _get_candidates_for_resource(self, cr, uid, res_model, res_id,
|
||||
context=None):
|
||||
'''return directories that can be chosen for a certain record of a
|
||||
certain model - called by js api, override as needed'''
|
||||
result = []
|
||||
for this in self.browse(
|
||||
cr, uid,
|
||||
self.search(
|
||||
cr, uid,
|
||||
[
|
||||
('type', '=', 'directory'),
|
||||
('ressource_type_id.model', '=', res_model),
|
||||
],
|
||||
context=context),
|
||||
context=context):
|
||||
#TODO: add write tests
|
||||
result.append(this)
|
||||
return result
|
||||
|
||||
def get_candidates_for_resource(self, cr, uid, res_model, res_id,
|
||||
context=None):
|
||||
'''return directories that can be chosen for a certain record of a
|
||||
certain model - js api'''
|
||||
result = []
|
||||
for this in self._get_candidates_for_resource(
|
||||
cr, uid, res_model, res_id, context=context):
|
||||
result.append({
|
||||
'id': this.id,
|
||||
'name': this.name_get()[0][1],
|
||||
})
|
||||
return result
|
||||
|
||||
def _register_hook(self, cr):
|
||||
from openerp.addons.web.http import httprequest
|
||||
from openerp.addons.web.controllers.main import Binary
|
||||
original = Binary.upload_attachment
|
||||
@httprequest
|
||||
def upload_attachment(self, req, callback, model, id, ufile,
|
||||
directory_id=None):
|
||||
if directory_id:
|
||||
# we can't use default_parent_id because of
|
||||
# the ir_attachment.create overwrite in document
|
||||
req.context['parent_id'] = int(directory_id)
|
||||
# fallback if the aboev is ever fixed
|
||||
req.context['default_parent_id'] = int(directory_id)
|
||||
return original(self, req, callback, model, id, ufile)
|
||||
|
||||
Binary.upload_attachment = upload_attachment
|
55
document_choose_directory/model/ir_attachment.py
Normal file
55
document_choose_directory/model/ir_attachment.py
Normal file
@ -0,0 +1,55 @@
|
||||
# -*- 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 openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
|
||||
|
||||
class IrAttachment(Model):
|
||||
_inherit = 'ir.attachment'
|
||||
|
||||
def _auto_init(self, cr, context=None):
|
||||
'''drop filename_unique if it exists and prevent it from being
|
||||
created'''
|
||||
cr.execute('''SELECT
|
||||
conname, pg_catalog.pg_get_constraintdef(oid, true) as condef
|
||||
FROM pg_constraint where conname=%s''',
|
||||
('ir_attachment_filename_unique',))
|
||||
if cr.fetchone():
|
||||
cr.execute(
|
||||
'ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (
|
||||
self._table, 'ir_attachment_filename_unique'))
|
||||
self._sql_constraints = filter(
|
||||
lambda x: x[0] != 'filename_unique', self._sql_constraints)
|
||||
return super(IrAttachment, self)._auto_init(cr, context=context)
|
||||
|
||||
def read(self, cr, uid, ids, fields_to_read=None, context=None,
|
||||
load='_classic_read'):
|
||||
'''inject the extra field we need in the web client. This saves us a
|
||||
couple of extra client side calls'''
|
||||
if fields_to_read == ['name', 'url', 'type', 'create_uid',
|
||||
'create_date', 'write_uid', 'write_date']:
|
||||
fields_to_read = fields_to_read + ['parent_id']
|
||||
result = super(IrAttachment, self).read(
|
||||
cr, uid, ids, fields_to_read=fields_to_read, context=context,
|
||||
load=load)
|
||||
return result
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
.openerp .oe_sidebar .oe_dropdown_menu .oe_sidebar_add_attachment .oe_hidden_input_file,
|
||||
.oe_sidebar_add_attachment .oe_form_binary_form
|
||||
{
|
||||
width: 100%;
|
||||
}
|
||||
.oe_sidebar_add_attachment .oe_form_binary_form select
|
||||
{
|
||||
display: block;
|
||||
min-width: 100%;
|
||||
}
|
||||
.openerp .oe_sidebar_add_attachment .oe_hidden_input_file input.oe_form_binary_file
|
||||
{
|
||||
top: 2em;
|
||||
}
|
||||
.openerp .oe_sidebar .oe_dropdown_menu .oe_sidebar_add_attachment
|
||||
{
|
||||
height: 3.5em;
|
||||
}
|
||||
li.oe_attachment_directory
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
.openerp .oe_dropdown_menu > li.oe_attachment_directory:hover
|
||||
{
|
||||
background-color: inherit;
|
||||
background-image: inherit;
|
||||
box-shadow: none;
|
||||
}
|
||||
.openerp .oe_dropdown_menu > li.oe_attachment_directory a:hover
|
||||
{
|
||||
cursor: default !important;
|
||||
}
|
BIN
document_choose_directory/static/src/img/icon.png
Normal file
BIN
document_choose_directory/static/src/img/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
@ -0,0 +1,84 @@
|
||||
//-*- 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/>.
|
||||
//
|
||||
//############################################################################
|
||||
|
||||
openerp.document_choose_directory = function(instance)
|
||||
{
|
||||
instance.web.Sidebar.include(
|
||||
{
|
||||
init: function()
|
||||
{
|
||||
this._super.apply(this, arguments);
|
||||
this.directory_candidates = [];
|
||||
},
|
||||
do_attachement_update: function(dataset, model_id, args)
|
||||
{
|
||||
var document_folder = new instance.web.Model(
|
||||
'document.directory', dataset.get_context()),
|
||||
self = this,
|
||||
_super = this._super;
|
||||
return document_folder.call(
|
||||
'get_candidates_for_resource', [dataset.model, model_id])
|
||||
.then(function(records)
|
||||
{
|
||||
self.directory_candidates = records;
|
||||
self.$el.on(
|
||||
//suppress html's onclick event that would close the
|
||||
//menu
|
||||
'click', 'select[name="directory_id"]',
|
||||
function(e) {e.stopPropagation()});
|
||||
})
|
||||
.then(function()
|
||||
{
|
||||
_super.apply(self, [dataset, model_id, args]);
|
||||
});
|
||||
},
|
||||
on_attachments_loaded: function(attachments)
|
||||
{
|
||||
var attachments_per_directory = [];
|
||||
_.chain(attachments)
|
||||
.groupBy(
|
||||
function(a) { return a.parent_id[0] })
|
||||
.each(
|
||||
function(group)
|
||||
{
|
||||
attachments_per_directory.push({
|
||||
name: _.first(group).parent_id[1] ||
|
||||
instance.web._t('No directory'),
|
||||
classname: 'oe_attachment_directory',
|
||||
});
|
||||
_(group).each(function(a)
|
||||
{
|
||||
attachments_per_directory.push(a);
|
||||
});
|
||||
});
|
||||
|
||||
return this._super(attachments_per_directory);
|
||||
},
|
||||
get_directory_items: function(items)
|
||||
{
|
||||
return _(items).filter(
|
||||
function(i)
|
||||
{
|
||||
return i.classname == 'oe_attachment_directory';
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-extend="Sidebar">
|
||||
<t t-jquery=".oe_sidebar_add_attachment span" t-operation="before">
|
||||
<select name="directory_id">
|
||||
<option value="" selected="selected">Choose directory</option>
|
||||
<option t-foreach="widget.directory_candidates" t-as="directory" t-att-value="directory.id">
|
||||
<t t-esc="directory.name" />
|
||||
</option>
|
||||
</select>
|
||||
</t>
|
||||
<t t-jquery=".oe_sidebar_delete_item">
|
||||
this.attr('t-if', "section.name == 'files' and !item.callback and item.classname != 'oe_attachment_directory'");
|
||||
</t>
|
||||
<t t-jquery="button.oe_dropdown_toggle t[t-if]">
|
||||
this.attr('t-raw', "(widget.items[section.name].length - widget.get_directory_items(widget.items[section.name]).length) || ''");
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
20
document_choose_directory/view/document_directory.xml
Normal file
20
document_choose_directory/view/document_directory.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_document_directory_form" model="ir.ui.view">
|
||||
<field name="model">document.directory</field>
|
||||
<field name="inherit_id" ref="document.view_document_directory_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[@string='Definition']/group[2]" position="attributes">
|
||||
<attribute name="attrs" />
|
||||
</xpath>
|
||||
<xpath expr="//page[@string='Definition']/group[2]/field[@name='resource_field']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('type', '!=', 'ressource')]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//page[@string='Definition']/group[2]/field[@name='ressource_tree']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('type', '!=', 'ressource')]}</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue
Block a user