[IMP] document_page_tag: black, isort, prettier

This commit is contained in:
manu 2022-03-07 13:41:52 +01:00 committed by angel
parent 0390610a9b
commit b080e113fd
6 changed files with 54 additions and 37 deletions

View File

@ -9,13 +9,11 @@
"category": "Knowledge Management", "category": "Knowledge Management",
"summary": "Allows you to assign tags or keywords to pages and search for " "summary": "Allows you to assign tags or keywords to pages and search for "
"them afterwards", "them afterwards",
"depends": [ "depends": ["document_page",],
'document_page',
],
"data": [ "data": [
"views/document_page_tag.xml", "views/document_page_tag.xml",
"views/document_page.xml", "views/document_page.xml",
'security/ir.model.access.csv', "security/ir.model.access.csv",
], ],
"installable": True, "installable": True,
} }

View File

@ -1,9 +1,9 @@
# Copyright 2015-2018 Therp BV <https://therp.nl> # Copyright 2015-2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models, fields from odoo import fields, models
class DocumentPage(models.Model): class DocumentPage(models.Model):
_inherit = 'document.page' _inherit = "document.page"
tag_ids = fields.Many2many('document.page.tag', string='Keywords') tag_ids = fields.Many2many("document.page.tag", string="Keywords")

View File

@ -1,24 +1,24 @@
# Copyright 2015-2018 Therp BV <https://therp.nl> # Copyright 2015-2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models, fields from odoo import api, fields, models
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(required=True, translate=True) name = fields.Char(required=True, translate=True)
color = fields.Integer(string='Color Index') color = fields.Integer(string="Color Index")
active = fields.Boolean(default=True) active = fields.Boolean(default=True)
_sql_constraints = [ _sql_constraints = [
('unique_name', 'unique(name)', 'Tags must me unique'), ("unique_name", "unique(name)", "Tags must me unique"),
] ]
@api.model @api.model
def create(self, vals): def create(self, vals):
"""Be nice when trying to create duplicates""" """Be nice when trying to create duplicates"""
existing = self.search([('name', '=ilike', vals['name'])], limit=1) existing = self.search([("name", "=ilike", vals["name"])], limit=1)
if existing: if existing:
return existing return existing
return super(DocumentPageTag, self).create(vals) return super(DocumentPageTag, self).create(vals)

View File

@ -1,21 +1,20 @@
# Copyright 2015-2018 Therp BV <https://therp.nl> # Copyright 2015-2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from psycopg2 import IntegrityError from psycopg2 import IntegrityError
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
from odoo.tools.misc import mute_logger from odoo.tools.misc import mute_logger
class TestDocumentPageTag(TransactionCase): class TestDocumentPageTag(TransactionCase):
def test_document_page_tag(self): def test_document_page_tag(self):
testtag = self.env['document.page.tag'].name_create('test') testtag = self.env["document.page.tag"].name_create("test")
# check we're charitable on duplicates # check we're charitable on duplicates
self.assertEqual( self.assertEqual(
testtag, self.env['document.page.tag'].name_create('Test'), 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('odoo.sql_db'): with mute_logger("odoo.sql_db"):
testtag2 = self.env['document.page.tag'].create({ testtag2 = self.env["document.page.tag"].create({"name": "test2",})
'name': 'test2', testtag2.write({"name": "test"})
})
testtag2.write({'name': 'test'})

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="view_wiki_form" model="ir.ui.view"> <record id="view_wiki_form" model="ir.ui.view">
@ -6,7 +6,11 @@
<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" options="{'color_field': 'color', 'no_create_edit': True}"/> <field
name="tag_ids"
widget="many2many_tags"
options="{'color_field': 'color', 'no_create_edit': True}"
/>
</field> </field>
</field> </field>
</record> </record>
@ -24,14 +28,16 @@
<record id="document_page_tag_view_inherit_list" model="ir.ui.view"> <record id="document_page_tag_view_inherit_list" model="ir.ui.view">
<field name="name">document_page.tags.tree</field> <field name="name">document_page.tags.tree</field>
<field name="model">document.page</field> <field name="model">document.page</field>
<field name="inherit_id" ref="document_page.view_wiki_tree"/> <field name="inherit_id" ref="document_page.view_wiki_tree" />
<field name="type">tree</field> <field name="type">tree</field>
<field name="field_parent">child_ids</field> <field name="field_parent">child_ids</field>
<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" <field
widget="many2many_tags" name="tag_ids"
options="{'color_field': 'color'}"/> widget="many2many_tags"
options="{'color_field': 'color'}"
/>
</field> </field>
</field> </field>
</record> </record>

View File

@ -5,8 +5,12 @@
<field name="model">document.page.tag</field> <field name="model">document.page.tag</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Document Tag Search"> <search string="Document Tag Search">
<filter string="Archived" name="inactive" domain="[('active','=',False)]" /> <filter
<separator/> string="Archived"
name="inactive"
domain="[('active','=',False)]"
/>
<separator />
<field name="name" filter_domain="[('name', 'ilike', self)]" /> <field name="name" filter_domain="[('name', 'ilike', self)]" />
</search> </search>
</field> </field>
@ -19,14 +23,23 @@
<form string="Tag"> <form string="Tag">
<sheet> <sheet>
<div class="oe_button_box" name="button_box"> <div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-check"> <button
<field name="active" widget="boolean_button" options="{&quot;terminology&quot;: &quot;active&quot;}" /> name="toggle_active"
type="object"
class="oe_stat_button"
icon="fa-check"
>
<field
name="active"
widget="boolean_button"
options="{&quot;terminology&quot;: &quot;active&quot;}"
/>
</button> </button>
</div> </div>
<div class="oe_title"> <div class="oe_title">
<label for="name" class="oe_edit_only" /> <label for="name" class="oe_edit_only" />
<h1> <h1>
<field name="name" required="1"/> <field name="name" required="1" />
</h1> </h1>
</div> </div>
<group name="main"> <group name="main">
@ -55,11 +68,12 @@
<field name="view_type">form</field> <field name="view_type">form</field>
</record> </record>
<menuitem <menuitem
id="document_page_tag_menu" id="document_page_tag_menu"
name="Tags" name="Tags"
parent="knowledge.menu_document_configuration" parent="knowledge.menu_document_configuration"
action="document_page_tag_action" action="document_page_tag_action"
sequence="45" /> sequence="45"
/>
</odoo> </odoo>