mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-27 19:08:42 -06:00
[IMP] document_url: black, isort
This commit is contained in:
parent
d54e23d812
commit
7cdb818e4b
@ -2,22 +2,14 @@
|
||||
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
{
|
||||
'name': 'URL attachment',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Tools',
|
||||
'author': "Tecnativa,"
|
||||
"Odoo Community Association (OCA)",
|
||||
'website': 'https://github.com/OCA/knowledge',
|
||||
'license': 'AGPL-3',
|
||||
'depends': [
|
||||
'document',
|
||||
],
|
||||
'data': [
|
||||
'view/document_url_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/url.xml',
|
||||
],
|
||||
'installable': True,
|
||||
"name": "URL attachment",
|
||||
"version": "12.0.1.0.0",
|
||||
"category": "Tools",
|
||||
"author": "Tecnativa," "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/knowledge",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["document",],
|
||||
"data": ["view/document_url_view.xml", "security/ir.model.access.csv",],
|
||||
"qweb": ["static/src/xml/url.xml",],
|
||||
"installable": True,
|
||||
}
|
||||
|
@ -4,10 +4,10 @@
|
||||
* Copyright 2019 Tecnativa - Ernesto Tejeda
|
||||
* 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";
|
||||
|
||||
var AttachmentBox = require('mail.AttachmentBox');
|
||||
var AttachmentBox = require("mail.AttachmentBox");
|
||||
|
||||
AttachmentBox.include({
|
||||
events: _.extend(AttachmentBox.prototype.events, {
|
||||
@ -20,11 +20,11 @@ odoo.define('document_url', function (require) {
|
||||
* @param {MouseEvent} 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: {
|
||||
'active_id': this.currentResID,
|
||||
'active_ids': [this.currentResID],
|
||||
'active_model': this.currentResModel,
|
||||
active_id: this.currentResID,
|
||||
active_ids: [this.currentResID],
|
||||
active_model: this.currentResModel,
|
||||
},
|
||||
on_close: this._onAddedUrl.bind(this),
|
||||
});
|
||||
@ -33,7 +33,7 @@ odoo.define('document_url', function (require) {
|
||||
* @private
|
||||
*/
|
||||
_onAddedUrl: function() {
|
||||
this.trigger_up('reload_attachment_box');
|
||||
}
|
||||
this.trigger_up("reload_attachment_box");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -2,11 +2,11 @@
|
||||
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda
|
||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
<t t-extend="mail.chatter.AttachmentBox">
|
||||
<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>
|
||||
|
||||
</templates>
|
||||
|
@ -6,25 +6,24 @@ from odoo.tests import common
|
||||
class TestDocumentUrl(common.TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestDocumentUrl, self).setUp()
|
||||
wizard_add_url = self.env['ir.attachment.add_url']
|
||||
wizard_add_url = self.env["ir.attachment.add_url"]
|
||||
ctx = {
|
||||
'active_model': 'res.users',
|
||||
'active_id': self.env.ref('base.user_demo').id,
|
||||
'active_ids': [self.env.ref('base.user_demo').id]
|
||||
"active_model": "res.users",
|
||||
"active_id": 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({
|
||||
'name': 'Demo User (Website)',
|
||||
'url': 'http://www.odoodemouser.com'
|
||||
})
|
||||
self.wizard_add_url = wizard_add_url.with_context(ctx).create(
|
||||
{"name": "Demo User (Website)", "url": "http://www.odoodemouser.com"}
|
||||
)
|
||||
|
||||
def test_add_url_attachment(self):
|
||||
self.wizard_add_url.action_add_url()
|
||||
domain = [
|
||||
('type', '=', 'url'),
|
||||
('name', '=', 'Demo User (Website)'),
|
||||
('url', '=', 'http://www.odoodemouser.com'),
|
||||
('res_model', '=', 'res.users'),
|
||||
('res_id', '=', self.env.ref('base.user_demo').id)
|
||||
("type", "=", "url"),
|
||||
("name", "=", "Demo User (Website)"),
|
||||
("url", "=", "http://www.odoodemouser.com"),
|
||||
("res_model", "=", "res.users"),
|
||||
("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)
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<template id="assets_backend" name="google_drive assets" inherit_id="web.assets_backend">
|
||||
<template
|
||||
id="assets_backend"
|
||||
name="google_drive assets"
|
||||
inherit_id="web.assets_backend"
|
||||
>
|
||||
<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>
|
||||
</template>
|
||||
|
||||
<record model='ir.actions.act_window' id='action_ir_attachment_add_url'>
|
||||
<field name='name'>Add URL</field>
|
||||
<field name='res_model'>ir.attachment.add_url</field>
|
||||
@ -15,7 +17,6 @@
|
||||
<field name='view_type'>form</field>
|
||||
<field name='view_mode'>form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_ir_attachment_add_url_form">
|
||||
<field name="name">ir.attachment.add_url.form</field>
|
||||
<field name="model">ir.attachment.add_url</field>
|
||||
@ -26,12 +27,16 @@
|
||||
<field name="url" widget="url" />
|
||||
</group>
|
||||
<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
|
||||
<button special="cancel" string="Cancel" class="oe_link" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
@ -1,33 +1,34 @@
|
||||
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
|
||||
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
from odoo import fields, models
|
||||
from urllib import parse
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class AddUrlWizard(models.Model):
|
||||
_name = 'ir.attachment.add_url'
|
||||
_description = 'Wizard to add URL attachment'
|
||||
_name = "ir.attachment.add_url"
|
||||
_description = "Wizard to add URL attachment"
|
||||
|
||||
name = fields.Char('Name', required=True)
|
||||
url = fields.Char('URL', required=True)
|
||||
name = fields.Char("Name", required=True)
|
||||
url = fields.Char("URL", required=True)
|
||||
|
||||
def action_add_url(self):
|
||||
"""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
|
||||
attachment_obj = self.env['ir.attachment']
|
||||
attachment_obj = self.env["ir.attachment"]
|
||||
for form in self:
|
||||
url = parse.urlparse(form.url)
|
||||
if not url.scheme:
|
||||
url = parse.urlparse('%s%s' % ('http://', form.url))
|
||||
for active_id in self.env.context.get('active_ids', []):
|
||||
url = parse.urlparse("{}{}".format("http://", form.url))
|
||||
for active_id in self.env.context.get("active_ids", []):
|
||||
attachment = {
|
||||
'name': form.name,
|
||||
'type': 'url',
|
||||
'url': url.geturl(),
|
||||
'res_id': active_id,
|
||||
'res_model': self.env.context['active_model'],
|
||||
"name": form.name,
|
||||
"type": "url",
|
||||
"url": url.geturl(),
|
||||
"res_id": active_id,
|
||||
"res_model": self.env.context["active_model"],
|
||||
}
|
||||
attachment_obj.create(attachment)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
return {"type": "ir.actions.act_window_close"}
|
||||
|
Loading…
Reference in New Issue
Block a user