mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-19 11:52:18 -06:00
[MIG] document_url: Migration to 11.0
This commit is contained in:
@@ -1,42 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
|
||||
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
||||
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
from openerp.osv import fields, orm
|
||||
try:
|
||||
# Python 3
|
||||
from urllib import parse as urlparse
|
||||
except:
|
||||
from urlparse import urlparse
|
||||
from odoo import fields, models
|
||||
from urllib import parse
|
||||
|
||||
|
||||
class AddUrlWizard(orm.TransientModel):
|
||||
class AddUrlWizard(models.Model):
|
||||
_name = 'ir.attachment.add_url'
|
||||
|
||||
_columns = {
|
||||
'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, cr, uid, ids, context=None):
|
||||
def action_add_url(self):
|
||||
"""Adds the URL with the given name as an ir.attachment record."""
|
||||
if context is None:
|
||||
context = {}
|
||||
if not context.get('active_model'):
|
||||
if not self.env.context.get('active_model'):
|
||||
return
|
||||
attachment_obj = self.pool['ir.attachment']
|
||||
for form in self.browse(cr, uid, ids, context=context):
|
||||
url = urlparse(form.url)
|
||||
attachment_obj = self.env['ir.attachment']
|
||||
for form in self:
|
||||
url = parse.urlparse(form.url)
|
||||
if not url.scheme:
|
||||
url = urlparse('%s%s' % ('http://', form.url))
|
||||
for active_id in context.get('active_ids', []):
|
||||
url = parse.urlparse('%s%s' % ('http://', form.url))
|
||||
for active_id in self.env.context.get('active_ids', []):
|
||||
attachment = {
|
||||
'name': form.name,
|
||||
'type': 'url',
|
||||
'url': url.geturl(),
|
||||
'user_id': uid,
|
||||
'res_id': active_id,
|
||||
'res_model': context['active_model'],
|
||||
'res_model': self.env.context['active_model'],
|
||||
}
|
||||
attachment_obj.create(cr, uid, attachment, context=context)
|
||||
attachment_obj.create(attachment)
|
||||
return {'type': 'ir.actions.act_close_wizard_and_reload_view'}
|
||||
|
||||
Reference in New Issue
Block a user