[IMP] document_page_tag: black, isort, prettier

This commit is contained in:
manu 2022-03-07 13:41:52 +01:00 committed by FernandoRomera
parent 8192457e2d
commit 5523b2e6bf
6 changed files with 54 additions and 37 deletions

View File

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

View File

@ -1,9 +1,9 @@
# Copyright 2015-2018 Therp BV <https://therp.nl>
# 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):
_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>
# 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):
_name = 'document.page.tag'
_description = 'A keyword for document pages'
_name = "document.page.tag"
_description = "A keyword for document pages"
name = fields.Char(required=True, translate=True)
color = fields.Integer(string='Color Index')
color = fields.Integer(string="Color Index")
active = fields.Boolean(default=True)
_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'])], limit=1)
existing = self.search([("name", "=ilike", vals["name"])], limit=1)
if existing:
return existing
return super(DocumentPageTag, self).create(vals)

View File

@ -1,21 +1,20 @@
# Copyright 2015-2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from psycopg2 import IntegrityError
from odoo.tests.common import TransactionCase
from odoo.tools.misc import mute_logger
class TestDocumentPageTag(TransactionCase):
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
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
with self.assertRaises(IntegrityError):
with mute_logger('odoo.sql_db'):
testtag2 = self.env['document.page.tag'].create({
'name': 'test2',
})
testtag2.write({'name': 'test'})
with mute_logger("odoo.sql_db"):
testtag2 = self.env["document.page.tag"].create({"name": "test2",})
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>
<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="arch" type="xml">
<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>
</record>
@ -24,14 +28,16 @@
<record id="document_page_tag_view_inherit_list" model="ir.ui.view">
<field name="name">document_page.tags.tree</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="field_parent">child_ids</field>
<field name="arch" type="xml">
<field name="parent_id" position="after">
<field name="tag_ids"
<field
name="tag_ids"
widget="many2many_tags"
options="{'color_field': 'color'}"/>
options="{'color_field': 'color'}"
/>
</field>
</field>
</record>

View File

@ -5,8 +5,12 @@
<field name="model">document.page.tag</field>
<field name="arch" type="xml">
<search string="Document Tag Search">
<filter string="Archived" name="inactive" domain="[('active','=',False)]" />
<separator/>
<filter
string="Archived"
name="inactive"
domain="[('active','=',False)]"
/>
<separator />
<field name="name" filter_domain="[('name', 'ilike', self)]" />
</search>
</field>
@ -19,14 +23,23 @@
<form string="Tag">
<sheet>
<div class="oe_button_box" name="button_box">
<button 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
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>
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" required="1"/>
<field name="name" required="1" />
</h1>
</div>
<group name="main">
@ -60,6 +73,7 @@
name="Tags"
parent="knowledge.menu_document_configuration"
action="document_page_tag_action"
sequence="45" />
sequence="45"
/>
</odoo>