mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-18 13:06:34 -06:00
[MIG] document_page_tags
This commit is contained in:
parent
621d5284cd
commit
2767b218bf
@ -1,21 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# Copyright 2015-2018 Therp BV <https://therp.nl>
|
||||||
#
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
# 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 . import models
|
||||||
from .hooks import post_init_hook
|
|
||||||
|
21
document_page_tags/__manifest__.py
Normal file
21
document_page_tags/__manifest__.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2015-2018 Therp BV <https://therp.nl>
|
||||||
|
# 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,
|
||||||
|
}
|
@ -1,37 +0,0 @@
|
|||||||
# -*- 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',
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
# -*- 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']
|
|
||||||
# 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))]})
|
|
@ -1,21 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# Copyright 2015-2018 Therp BV <https://therp.nl>
|
||||||
#
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
# 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
|
||||||
from . import document_page_tag
|
from . import document_page_tag
|
||||||
|
@ -1,22 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# Copyright 2015-2018 Therp BV <https://therp.nl>
|
||||||
#
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
# 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
|
from openerp import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,31 +1,23 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# Copyright 2015-2018 Therp BV <https://therp.nl>
|
||||||
#
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
|
from openerp import api, models, fields
|
||||||
#
|
|
||||||
# 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):
|
class DocumentPageTag(models.Model):
|
||||||
_name = 'document.page.tag'
|
_name = 'document.page.tag'
|
||||||
_description = 'A keyword for document pages'
|
_description = 'A keyword for document pages'
|
||||||
|
|
||||||
name = fields.Char(translate=True)
|
name = fields.Char(required=True, translate=True)
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
('unique_name', 'unique(name)', 'Tags must me unique'),
|
('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)
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
"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_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
|
||||||
|
|
@ -1,34 +1,22 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# Copyright 2015-2018 Therp BV <https://therp.nl>
|
||||||
#
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
# 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 psycopg2 import IntegrityError
|
||||||
from openerp.tests.common import TransactionCase
|
from openerp.tests.common import TransactionCase
|
||||||
from ..hooks import post_init_hook
|
|
||||||
from openerp.tools.misc import mute_logger
|
from openerp.tools.misc import mute_logger
|
||||||
|
|
||||||
|
|
||||||
class TestDocumentPageTags(TransactionCase):
|
class TestDocumentPageTags(TransactionCase):
|
||||||
def test_document_page_tags(self):
|
def test_document_page_tags(self):
|
||||||
# run our init hook for coverage
|
testtag = self.env['document.page.tag'].name_create('test')
|
||||||
post_init_hook(self.cr, self.registry)
|
# check we're charitable on duplicates
|
||||||
|
self.assertEqual(
|
||||||
|
testtag, self.env['document.page.tag'].name_create('Test'),
|
||||||
|
)
|
||||||
# check we can't create nonunique tags
|
# check we can't create nonunique tags
|
||||||
with self.assertRaises(IntegrityError):
|
with self.assertRaises(IntegrityError):
|
||||||
with mute_logger('openerp.sql_db'):
|
with mute_logger('odoo.sql_db'):
|
||||||
self.env['document.page.tag'].name_create('test')
|
testtag2 = self.env['document.page.tag'].create({
|
||||||
self.env['document.page.tag'].name_create('test')
|
'name': 'test2',
|
||||||
|
})
|
||||||
|
testtag2.write({'name': 'test'})
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
<record id="view_wiki_form" model="ir.ui.view">
|
||||||
<record id="view_wiki_form" model="ir.ui.view">
|
<field name="model">document.page</field>
|
||||||
<field name="model">document.page</field>
|
<field name="inherit_id" ref="document_page.view_wiki_form" />
|
||||||
<field name="inherit_id" ref="document_page.view_wiki_form" />
|
<field name="arch" type="xml">
|
||||||
<field name="arch" type="xml">
|
<field name="parent_id" position="after">
|
||||||
<field name="parent_id" position="after">
|
<field name="tag_ids" widget="many2many_tags" />
|
||||||
<field name="tag_ids" widget="many2many_tags" />
|
|
||||||
</field>
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</field>
|
||||||
<record id="view_wiki_filter" model="ir.ui.view">
|
</record>
|
||||||
<field name="model">document.page</field>
|
<record id="view_wiki_filter" model="ir.ui.view">
|
||||||
<field name="inherit_id" ref="document_page.view_wiki_filter" />
|
<field name="model">document.page</field>
|
||||||
<field name="arch" type="xml">
|
<field name="inherit_id" ref="document_page.view_wiki_filter" />
|
||||||
<field name="name" position="after">
|
<field name="arch" type="xml">
|
||||||
<field name="tag_ids" widget="many2one" />
|
<field name="name" position="after">
|
||||||
</field>
|
<field name="tag_ids" widget="many2one" />
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</field>
|
||||||
</data>
|
</record>
|
||||||
</openerp>
|
</odoo>
|
||||||
|
13
document_page_tags/views/document_page_tag.xml
Normal file
13
document_page_tags/views/document_page_tag.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_document_page_tag_form" model="ir.ui.view">
|
||||||
|
<field name="model">document.page.tag</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form>
|
||||||
|
<group>
|
||||||
|
<field name="name" />
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
Loading…
Reference in New Issue
Block a user