diff --git a/document_page_tags/__init__.py b/document_page_tags/__init__.py index 856516ef..289e8cdb 100644 --- a/document_page_tags/__init__.py +++ b/document_page_tags/__init__.py @@ -1,21 +1,4 @@ # -*- 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 . -# -############################################################################## +# Copyright 2015-2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models -from .hooks import post_init_hook diff --git a/document_page_tags/__manifest__.py b/document_page_tags/__manifest__.py new file mode 100644 index 00000000..77b3cb20 --- /dev/null +++ b/document_page_tags/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2015-2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Tags/Keywords for document page", + "version": "10.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_tag.xml", + "views/document_page.xml", + 'security/ir.model.access.csv', + ], + "installable": True, +} diff --git a/document_page_tags/__openerp__.py b/document_page_tags/__openerp__.py deleted file mode 100644 index b82c7183..00000000 --- a/document_page_tags/__openerp__.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- 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 deleted file mode 100644 index fdd8fcbb..00000000 --- a/document_page_tags/hooks.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- 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'] - # pylint: disable=E8103 - 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 index c7ac18cb..7911c6a6 100644 --- a/document_page_tags/models/__init__.py +++ b/document_page_tags/models/__init__.py @@ -1,21 +1,5 @@ # -*- 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 . -# -############################################################################## +# Copyright 2015-2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). 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 index 5f0ed038..0358ac14 100644 --- a/document_page_tags/models/document_page.py +++ b/document_page_tags/models/document_page.py @@ -1,22 +1,6 @@ # -*- 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 . -# -############################################################################## +# Copyright 2015-2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from openerp import models, fields diff --git a/document_page_tags/models/document_page_tag.py b/document_page_tags/models/document_page_tag.py index e7540bc8..1229ff9a 100644 --- a/document_page_tags/models/document_page_tag.py +++ b/document_page_tags/models/document_page_tag.py @@ -1,31 +1,23 @@ # -*- 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 +# Copyright 2015-2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openerp import api, models, fields class DocumentPageTag(models.Model): _name = 'document.page.tag' _description = 'A keyword for document pages' - name = fields.Char(translate=True) + name = fields.Char(required=True, translate=True) _sql_constraints = [ ('unique_name', 'unique(name)', 'Tags must me unique'), ] + + @api.model + def create(self, vals): + """Be nice when trying to create duplicates""" + existing = self.search([('name', '=ilike', vals['name'])]) + if existing: + return existing + return super(DocumentPageTag, self).create(vals) diff --git a/document_page_tags/security/ir.model.access.csv b/document_page_tags/security/ir.model.access.csv index 0a0d36a0..baee8104 100644 --- a/document_page_tags/security/ir.model.access.csv +++ b/document_page_tags/security/ir.model.access.csv @@ -1,3 +1,3 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" access_document_page_tag_all,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 +access_document_page_tag,access_document_page_tag,model_document_page_tag,base.group_user,1,0,1,1 diff --git a/document_page_tags/tests/test_document_page_tags.py b/document_page_tags/tests/test_document_page_tags.py index 3b6251b9..7265a5f6 100644 --- a/document_page_tags/tests/test_document_page_tags.py +++ b/document_page_tags/tests/test_document_page_tags.py @@ -1,34 +1,22 @@ # -*- 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 . -# -############################################################################## +# Copyright 2015-2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from psycopg2 import IntegrityError from openerp.tests.common import TransactionCase -from ..hooks import post_init_hook from openerp.tools.misc import mute_logger class TestDocumentPageTags(TransactionCase): def test_document_page_tags(self): - # run our init hook for coverage - post_init_hook(self.cr, self.registry) + testtag = self.env['document.page.tag'].name_create('test') + # check we're charitable on duplicates + self.assertEqual( + testtag, self.env['document.page.tag'].name_create('Test'), + ) # check we can't create nonunique tags with self.assertRaises(IntegrityError): - with mute_logger('openerp.sql_db'): - self.env['document.page.tag'].name_create('test') - self.env['document.page.tag'].name_create('test') + with mute_logger('odoo.sql_db'): + testtag2 = self.env['document.page.tag'].create({ + 'name': 'test2', + }) + testtag2.write({'name': 'test'}) diff --git a/document_page_tags/views/document_page.xml b/document_page_tags/views/document_page.xml index e9693769..f7ed85fc 100644 --- a/document_page_tags/views/document_page.xml +++ b/document_page_tags/views/document_page.xml @@ -1,23 +1,21 @@ - - - - document.page - - - - - + + + document.page + + + + - - - document.page - - - - - + + + + document.page + + + + - - - + + + diff --git a/document_page_tags/views/document_page_tag.xml b/document_page_tags/views/document_page_tag.xml new file mode 100644 index 00000000..54545a5a --- /dev/null +++ b/document_page_tags/views/document_page_tag.xml @@ -0,0 +1,13 @@ + + + + document.page.tag + +
+ + + +
+
+
+