[IMP] document_url: black, isort

This commit is contained in:
Fernando La Chica 2020-10-22 13:51:38 +02:00
parent d54e23d812
commit 7cdb818e4b
6 changed files with 68 additions and 71 deletions

View File

@ -2,22 +2,14 @@
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
{ {
'name': 'URL attachment', "name": "URL attachment",
'version': '12.0.1.0.0', "version": "12.0.1.0.0",
'category': 'Tools', "category": "Tools",
'author': "Tecnativa," "author": "Tecnativa," "Odoo Community Association (OCA)",
"Odoo Community Association (OCA)", "website": "https://github.com/OCA/knowledge",
'website': 'https://github.com/OCA/knowledge', "license": "AGPL-3",
'license': 'AGPL-3', "depends": ["document",],
'depends': [ "data": ["view/document_url_view.xml", "security/ir.model.access.csv",],
'document', "qweb": ["static/src/xml/url.xml",],
], "installable": True,
'data': [
'view/document_url_view.xml',
'security/ir.model.access.csv',
],
'qweb': [
'static/src/xml/url.xml',
],
'installable': True,
} }

View File

@ -4,10 +4,10 @@
* Copyright 2019 Tecnativa - Ernesto Tejeda * Copyright 2019 Tecnativa - Ernesto Tejeda
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/ */
odoo.define('document_url', function (require) { odoo.define("document_url", function(require) {
"use strict"; "use strict";
var AttachmentBox = require('mail.AttachmentBox'); var AttachmentBox = require("mail.AttachmentBox");
AttachmentBox.include({ AttachmentBox.include({
events: _.extend(AttachmentBox.prototype.events, { events: _.extend(AttachmentBox.prototype.events, {
@ -19,12 +19,12 @@ odoo.define('document_url', function (require) {
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onAddUrl: function (ev) { _onAddUrl: function(ev) {
this.do_action('document_url.action_ir_attachment_add_url', { this.do_action("document_url.action_ir_attachment_add_url", {
additional_context: { additional_context: {
'active_id': this.currentResID, active_id: this.currentResID,
'active_ids': [this.currentResID], active_ids: [this.currentResID],
'active_model': this.currentResModel, active_model: this.currentResModel,
}, },
on_close: this._onAddedUrl.bind(this), on_close: this._onAddedUrl.bind(this),
}); });
@ -32,8 +32,8 @@ odoo.define('document_url', function (require) {
/** /**
* @private * @private
*/ */
_onAddedUrl: function () { _onAddedUrl: function() {
this.trigger_up('reload_attachment_box'); this.trigger_up("reload_attachment_box");
} },
}); });
}); });

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda <!-- Copyright 2018 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-extend="mail.chatter.AttachmentBox"> <t t-extend="mail.chatter.AttachmentBox">
<t t-jquery="span.o_upload_attachments_button" t-operation="after"> <t t-jquery="span.o_upload_attachments_button" t-operation="after">
<span class="btn btn-link o_add_url_button"><span class="fa fa-plus-square"/> Add URL</span> <span class="btn btn-link o_add_url_button"><span
class="fa fa-plus-square"
/> Add URL</span>
</t> </t>
</t> </t>
</templates> </templates>

View File

@ -6,25 +6,24 @@ from odoo.tests import common
class TestDocumentUrl(common.TransactionCase): class TestDocumentUrl(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestDocumentUrl, self).setUp() super(TestDocumentUrl, self).setUp()
wizard_add_url = self.env['ir.attachment.add_url'] wizard_add_url = self.env["ir.attachment.add_url"]
ctx = { ctx = {
'active_model': 'res.users', "active_model": "res.users",
'active_id': self.env.ref('base.user_demo').id, "active_id": self.env.ref("base.user_demo").id,
'active_ids': [self.env.ref('base.user_demo').id] "active_ids": [self.env.ref("base.user_demo").id],
} }
self.wizard_add_url = wizard_add_url.with_context(ctx).create({ self.wizard_add_url = wizard_add_url.with_context(ctx).create(
'name': 'Demo User (Website)', {"name": "Demo User (Website)", "url": "http://www.odoodemouser.com"}
'url': 'http://www.odoodemouser.com' )
})
def test_add_url_attachment(self): def test_add_url_attachment(self):
self.wizard_add_url.action_add_url() self.wizard_add_url.action_add_url()
domain = [ domain = [
('type', '=', 'url'), ("type", "=", "url"),
('name', '=', 'Demo User (Website)'), ("name", "=", "Demo User (Website)"),
('url', '=', 'http://www.odoodemouser.com'), ("url", "=", "http://www.odoodemouser.com"),
('res_model', '=', 'res.users'), ("res_model", "=", "res.users"),
('res_id', '=', self.env.ref('base.user_demo').id) ("res_id", "=", self.env.ref("base.user_demo").id),
] ]
attachment_added_count = self.env['ir.attachment'].search_count(domain) attachment_added_count = self.env["ir.attachment"].search_count(domain)
self.assertEqual(attachment_added_count, 1) self.assertEqual(attachment_added_count, 1)

View File

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<template
<template id="assets_backend" name="google_drive assets" inherit_id="web.assets_backend"> id="assets_backend"
name="google_drive assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/document_url/static/src/js/url.js"></script> <script type="text/javascript" src="/document_url/static/src/js/url.js" />
</xpath> </xpath>
</template> </template>
<record model='ir.actions.act_window' id='action_ir_attachment_add_url'> <record model='ir.actions.act_window' id='action_ir_attachment_add_url'>
<field name='name'>Add URL</field> <field name='name'>Add URL</field>
<field name='res_model'>ir.attachment.add_url</field> <field name='res_model'>ir.attachment.add_url</field>
@ -15,23 +17,26 @@
<field name='view_type'>form</field> <field name='view_type'>form</field>
<field name='view_mode'>form</field> <field name='view_mode'>form</field>
</record> </record>
<record model="ir.ui.view" id="view_ir_attachment_add_url_form"> <record model="ir.ui.view" id="view_ir_attachment_add_url_form">
<field name="name">ir.attachment.add_url.form</field> <field name="name">ir.attachment.add_url.form</field>
<field name="model">ir.attachment.add_url</field> <field name="model">ir.attachment.add_url</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Add URL"> <form string="Add URL">
<group> <group>
<field name="name"/> <field name="name" />
<field name="url" widget="url"/> <field name="url" widget="url" />
</group> </group>
<footer> <footer>
<button name="action_add_url" string="Add" class="oe_highlight" type="object" /> <button
name="action_add_url"
string="Add"
class="oe_highlight"
type="object"
/>
or or
<button special="cancel" string="Cancel" class="oe_link" /> <button special="cancel" string="Cancel" class="oe_link" />
</footer> </footer>
</form> </form>
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@ -1,33 +1,34 @@
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com) # Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) # Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
from odoo import fields, models
from urllib import parse from urllib import parse
from odoo import fields, models
class AddUrlWizard(models.Model): class AddUrlWizard(models.Model):
_name = 'ir.attachment.add_url' _name = "ir.attachment.add_url"
_description = 'Wizard to add URL attachment' _description = "Wizard to add URL attachment"
name = fields.Char('Name', required=True) name = fields.Char("Name", required=True)
url = fields.Char('URL', required=True) url = fields.Char("URL", required=True)
def action_add_url(self): def action_add_url(self):
"""Adds the URL with the given name as an ir.attachment record.""" """Adds the URL with the given name as an ir.attachment record."""
if not self.env.context.get('active_model'): if not self.env.context.get("active_model"):
return return
attachment_obj = self.env['ir.attachment'] attachment_obj = self.env["ir.attachment"]
for form in self: for form in self:
url = parse.urlparse(form.url) url = parse.urlparse(form.url)
if not url.scheme: if not url.scheme:
url = parse.urlparse('%s%s' % ('http://', form.url)) url = parse.urlparse("{}{}".format("http://", form.url))
for active_id in self.env.context.get('active_ids', []): for active_id in self.env.context.get("active_ids", []):
attachment = { attachment = {
'name': form.name, "name": form.name,
'type': 'url', "type": "url",
'url': url.geturl(), "url": url.geturl(),
'res_id': active_id, "res_id": active_id,
'res_model': self.env.context['active_model'], "res_model": self.env.context["active_model"],
} }
attachment_obj.create(attachment) attachment_obj.create(attachment)
return {'type': 'ir.actions.act_window_close'} return {"type": "ir.actions.act_window_close"}