mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-24 09:28:42 -06:00
[ADD] document_page_tags
This commit is contained in:
parent
9ae45f798b
commit
058b9a5692
48
document_page_tags/README.rst
Normal file
48
document_page_tags/README.rst
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
===============================
|
||||||
|
Tags/Keywords for document page
|
||||||
|
===============================
|
||||||
|
|
||||||
|
This module allows you to fill in keywords on your pages to simplify finding them afterwards.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
Fill in your keywords, and search for them by typing (part of) the keyword and choose searching for keywords.
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/118/8.0
|
||||||
|
|
||||||
|
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
|
||||||
|
`here <https://github.com/OCA/knowledge/issues/new?body=module:%20document_page_tags%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Holger Brunn <hbrunn@therp.nl>
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
To contribute to this module, please visit http://odoo-community.org.
|
21
document_page_tags/__init__.py
Normal file
21
document_page_tags/__init__.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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 models
|
||||||
|
from .hooks import post_init_hook
|
37
document_page_tags/__openerp__.py
Normal file
37
document_page_tags/__openerp__.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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": "Tags/Keywords for document page",
|
||||||
|
"version": "8.0.1.0.0",
|
||||||
|
"author": "Therp BV,Odoo Community Association (OCA)",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Knowledge Management",
|
||||||
|
"summary": "Allows you to assign tags or keywords to pages and search for "
|
||||||
|
"them afterwards",
|
||||||
|
"depends": [
|
||||||
|
'document_page',
|
||||||
|
],
|
||||||
|
"data": [
|
||||||
|
"views/document_page.xml",
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
],
|
||||||
|
"installable": True,
|
||||||
|
"post_init_hook": 'post_init_hook',
|
||||||
|
}
|
52
document_page_tags/hooks.py
Normal file
52
document_page_tags/hooks.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
import re
|
||||||
|
from openerp import SUPERUSER_ID
|
||||||
|
from openerp.api import Environment
|
||||||
|
|
||||||
|
|
||||||
|
def post_init_hook(cr, pool):
|
||||||
|
# in case we have an old tags column from the wiki module lying around,
|
||||||
|
# populate our tags with its content
|
||||||
|
for column in ['openupgrade_legacy_7_0_tags', 'tags']:
|
||||||
|
cr.execute('SELECT column_name FROM information_schema.columns '
|
||||||
|
'WHERE table_name=%s and column_name=%s',
|
||||||
|
(pool['document.page']._table, column))
|
||||||
|
if cr.fetchall():
|
||||||
|
populate_tags(cr, column)
|
||||||
|
|
||||||
|
|
||||||
|
def populate_tags(cr, column):
|
||||||
|
env = Environment(cr, SUPERUSER_ID, {})
|
||||||
|
document_page_tag = env['document.page.tag']
|
||||||
|
document_page = env['document.page']
|
||||||
|
cr.execute(
|
||||||
|
'SELECT %s, ARRAY_AGG(id) from %s WHERE %s IS NOT NULL GROUP BY %s' % (
|
||||||
|
column, env['document.page']._table, column, column))
|
||||||
|
for keywords, ids in cr.fetchall():
|
||||||
|
pages = document_page.browse(ids)
|
||||||
|
tag_ids = []
|
||||||
|
for keyword in re.split(r'\W+', keywords):
|
||||||
|
tag = document_page_tag.search([('name', '=ilike', keyword)])
|
||||||
|
if tag:
|
||||||
|
tag_ids.append(tag.id)
|
||||||
|
else:
|
||||||
|
tag_ids.append(document_page_tag.name_create(keyword)[0])
|
||||||
|
pages.write({'tag_ids': [(6, 0, set(tag_ids))]})
|
21
document_page_tags/models/__init__.py
Normal file
21
document_page_tags/models/__init__.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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_page
|
||||||
|
from . import document_page_tag
|
26
document_page_tags/models/document_page.py
Normal file
26
document_page_tags/models/document_page.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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 import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentPage(models.Model):
|
||||||
|
_inherit = 'document.page'
|
||||||
|
|
||||||
|
tag_ids = fields.Many2many('document.page.tag', string='Keywords')
|
31
document_page_tags/models/document_page_tag.py
Normal file
31
document_page_tags/models/document_page_tag.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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 import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentPageTag(models.Model):
|
||||||
|
_name = 'document.page.tag'
|
||||||
|
_description = 'A keyword for document pages'
|
||||||
|
|
||||||
|
name = fields.Char(translate=True)
|
||||||
|
|
||||||
|
_sql_constraints = [
|
||||||
|
('unique_name', 'unique(name)', 'Tags must me unique'),
|
||||||
|
]
|
3
document_page_tags/security/ir.model.access.csv
Normal file
3
document_page_tags/security/ir.model.access.csv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||||
|
access_document_page_tag,access_document_page_tag,model_document_page_tag,,1,0,0,0
|
||||||
|
access_document_page_tag,access_document_page_tag,model_document_page_tag,base.group_user,1,1,1,1
|
|
BIN
document_page_tags/static/description/icon.png
Normal file
BIN
document_page_tags/static/description/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
20
document_page_tags/tests/__init__.py
Normal file
20
document_page_tags/tests/__init__.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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 test_document_page_tags
|
32
document_page_tags/tests/test_document_page_tags.py
Normal file
32
document_page_tags/tests/test_document_page_tags.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# This module copyright (C) 2015 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 psycopg2 import IntegrityError
|
||||||
|
from openerp.tests.common import TransactionCase
|
||||||
|
from ..hooks import post_init_hook
|
||||||
|
|
||||||
|
|
||||||
|
class TestDocumentPageTags(TransactionCase):
|
||||||
|
def test_document_page_tags(self):
|
||||||
|
# run our init hook for coverage
|
||||||
|
post_init_hook(self.cr, self.registry)
|
||||||
|
# check we can't create nonunique tags
|
||||||
|
with self.assertRaises(IntegrityError):
|
||||||
|
self.env['document.page.tag'].name_create('test')
|
||||||
|
self.env['document.page.tag'].name_create('test')
|
23
document_page_tags/views/document_page.xml
Normal file
23
document_page_tags/views/document_page.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
<record id="view_wiki_form" model="ir.ui.view">
|
||||||
|
<field name="model">document.page</field>
|
||||||
|
<field name="inherit_id" ref="document_page.view_wiki_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="parent_id" position="after">
|
||||||
|
<field name="tag_ids" widget="many2many_tags" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
<record id="view_wiki_filter" model="ir.ui.view">
|
||||||
|
<field name="model">document.page</field>
|
||||||
|
<field name="inherit_id" ref="document_page.view_wiki_filter" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="name" position="after">
|
||||||
|
<field name="tag_ids" widget="many2one" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
Loading…
Reference in New Issue
Block a user