diff --git a/document_page_tags/README.rst b/document_page_tags/README.rst new file mode 100644 index 00000000..ebae1dcc --- /dev/null +++ b/document_page_tags/README.rst @@ -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 `_. +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 `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +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. diff --git a/document_page_tags/__init__.py b/document_page_tags/__init__.py new file mode 100644 index 00000000..856516ef --- /dev/null +++ b/document_page_tags/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +from . import models +from .hooks import post_init_hook diff --git a/document_page_tags/__openerp__.py b/document_page_tags/__openerp__.py new file mode 100644 index 00000000..b82c7183 --- /dev/null +++ b/document_page_tags/__openerp__.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +{ + "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', +} diff --git a/document_page_tags/hooks.py b/document_page_tags/hooks.py new file mode 100644 index 00000000..a68dfe54 --- /dev/null +++ b/document_page_tags/hooks.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +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))]}) diff --git a/document_page_tags/models/__init__.py b/document_page_tags/models/__init__.py new file mode 100644 index 00000000..c7ac18cb --- /dev/null +++ b/document_page_tags/models/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +from . import document_page +from . import document_page_tag diff --git a/document_page_tags/models/document_page.py b/document_page_tags/models/document_page.py new file mode 100644 index 00000000..5f0ed038 --- /dev/null +++ b/document_page_tags/models/document_page.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# 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 . +# +############################################################################## +from openerp import models, fields + + +class DocumentPage(models.Model): + _inherit = 'document.page' + + tag_ids = fields.Many2many('document.page.tag', string='Keywords') diff --git a/document_page_tags/models/document_page_tag.py b/document_page_tags/models/document_page_tag.py new file mode 100644 index 00000000..e7540bc8 --- /dev/null +++ b/document_page_tags/models/document_page_tag.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV (). +# +# 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 . +# +############################################################################## +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'), + ] diff --git a/document_page_tags/security/ir.model.access.csv b/document_page_tags/security/ir.model.access.csv new file mode 100644 index 00000000..f9dce761 --- /dev/null +++ b/document_page_tags/security/ir.model.access.csv @@ -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 diff --git a/document_page_tags/static/description/icon.png b/document_page_tags/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/document_page_tags/static/description/icon.png differ diff --git a/document_page_tags/tests/__init__.py b/document_page_tags/tests/__init__.py new file mode 100644 index 00000000..0816344d --- /dev/null +++ b/document_page_tags/tests/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +from . import test_document_page_tags diff --git a/document_page_tags/tests/test_document_page_tags.py b/document_page_tags/tests/test_document_page_tags.py new file mode 100644 index 00000000..5a1c2752 --- /dev/null +++ b/document_page_tags/tests/test_document_page_tags.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# This module copyright (C) 2015 Therp BV . +# +# 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 . +# +############################################################################## +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') diff --git a/document_page_tags/views/document_page.xml b/document_page_tags/views/document_page.xml new file mode 100644 index 00000000..e9693769 --- /dev/null +++ b/document_page_tags/views/document_page.xml @@ -0,0 +1,23 @@ + + + + + document.page + + + + + + + + + document.page + + + + + + + + +