Skip to content
Snippets Groups Projects
Commit 9f6ecb23 authored by Jérome Maes's avatar Jérome Maes
Browse files

[REF] website_*: clean method to override when using

parent 8a399930
No related branches found
No related tags found
No related merge requests found
Showing with 56 additions and 67 deletions
......@@ -676,17 +676,12 @@ class WebsitePublishedMixin(models.AbstractModel):
_name = "website.published.mixin"
website_published = fields.Boolean('Visible in Website', copy=False)
website_url = fields.Char('Website URL', compute='_website_url_proxy', help='The full URL to access the document through the website.')
# TODO remove proxy and _website_url unused arguments
def _website_url_proxy(self):
result = self._website_url(False, False)
for website in self:
website.website_url = result.get(website.id)
website_url = fields.Char('Website URL', compute='_compute_website_url', help='The full URL to access the document through the website.')
@api.multi
def _website_url(self, field_name, arg):
return dict.fromkeys(self.ids, '#')
def _compute_website_url(self):
for record in self:
record.website_url = '#'
@api.multi
def website_publish_button(self):
......
......@@ -11,6 +11,8 @@ from openerp.osv import osv, fields
from openerp.tools.translate import _
from openerp.tools.translate import html_translate
from odoo import api
class Blog(osv.Model):
_name = 'blog.blog'
......@@ -87,11 +89,11 @@ class BlogPost(osv.Model):
_order = 'id DESC'
_mail_post_access = 'read'
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = super(BlogPost, self)._website_url(cr, uid, ids, field_name, arg, context=context)
for blog_post in self.browse(cr, uid, ids, context=context):
res[blog_post.id] = "/blog/%s/post/%s" % (slug(blog_post.blog_id), slug(blog_post))
return res
@api.multi
def _compute_website_url(self):
super(BlogPost, self)._compute_website_url()
for blog_post in self:
blog_post.website_url = "/blog/%s/post/%s" % (slug(blog_post.blog_id), slug(blog_post))
def _compute_ranking(self, cr, uid, ids, name, arg, context=None):
res = {}
......
......@@ -17,11 +17,10 @@ class ResPartnerGrade(models.Model):
help="Gives the probability to assign a lead to this partner. (0 means no assignation.)")
@api.multi
def _website_url(self, field_name, arg):
res = super(ResPartnerGrade, self)._website_url(field_name, arg)
def _compute_website_url(self):
super(ResPartnerGrade, self)._compute_website_url()
for grade in self:
res[grade.id] = "/partners/grade/%s" % (slug(grade))
return res
grade.website_url = "/partners/grade/%s" % (slug(grade))
class ResPartnerActivation(models.Model):
......
......@@ -41,10 +41,10 @@ class Event(models.Model):
@api.multi
@api.depends('name')
def _website_url(self, name, arg):
res = super(Event, self)._website_url(name, arg)
res.update({(event.id, '/event/%s' % slug(event)) for event in self})
return res
def _compute_website_url(self):
super(Event, self)._compute_website_url()
for event in self:
event.website_url = '/event/%s' % slug(event)
@api.multi
def _get_new_menu_pages(self):
......
......@@ -82,10 +82,10 @@ class Track(models.Model):
@api.multi
@api.depends('name')
def _website_url(self, field_name, arg):
res = super(Track, self)._website_url(field_name, arg)
res.update({(track.id, '/event/%s/track/%s' % (slug(track.event_id), slug(track))) for track in self})
return res
def _compute_website_url(self):
super(Track, self)._compute_website_url()
for track in self:
track.website_url = '/event/%s/track/%s' % (slug(track.event_id), slug(track))
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
......
......@@ -10,7 +10,7 @@ class HrEmployee(models.Model):
public_info = fields.Char(string='Public Info')
@api.multi
def _website_url(self, field_name, arg):
res = super(HrEmployee, self)._website_url(field_name, arg)
res.update({(employee_id, '/page/website.aboutus#team') for employee_id in self.ids})
return res
def _compute_website_url(self):
super(HrEmployee, self)._compute_website_url()
for employee in self:
employee.website_url = '/page/website.aboutus#team'
......@@ -46,11 +46,10 @@ class Job(models.Model):
website_description = fields.Html('Website description', translate=html_translate, sanitize=False)
@api.multi
def _website_url(self, field_name, arg):
result = super(Job, self)._website_url(field_name, arg)
def _compute_website_url(self):
super(Job, self)._compute_website_url()
for job in self:
result[job.id] = "/jobs/detail/%s" % job.id
return result
job.website_url = "/jobs/detail/%s" % job.id
@api.multi
def set_open(self):
......
......@@ -9,12 +9,10 @@ class ImLivechatChannel(models.Model):
_name = 'im_livechat.channel'
_inherit = ['im_livechat.channel', 'website.published.mixin']
@api.v7
# TODO : when mixin in new api.v8, change this !
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = super(ImLivechatChannel, self)._website_url(cr, uid, ids, field_name, arg, context=context)
for channel in self.browse(cr, uid, ids, context=context):
res[channel.id] = "/livechat/channel/%s" % (slug(channel),)
return res
@api.multi
def _compute_website_url(self):
super(ImLivechatChannel, self)._compute_website_url()
for channel in self:
channel.website_url = "/livechat/channel/%s" % (slug(channel),)
website_description = fields.Html("Website description", default=False, help="Description of the channel displayed on the website page", sanitize=False, translate=html_translate)
......@@ -18,8 +18,7 @@ class WebsiteResPartner(models.Model):
self.self = self.id
@api.multi
def _website_url(self, field_name, arg):
res = super(WebsiteResPartner, self)._website_url(field_name, arg)
def _compute_website_url(self):
super(WebsiteResPartner, self)._compute_website_url()
for partner in self:
res[partner.id] = "/partners/%s" % slug(partner)
return res
partner.website_url = "/partners/%s" % slug(partner)
......@@ -19,8 +19,7 @@ class Project(models.Model):
}
@api.multi
def _website_url(self, field_name, arg):
res = dict()
def _compute_website_url(self):
super(Project, self)._compute_website_url()
for project in self:
res[project.id] = "/project/rating/%s" % project.id
return res
project.website_url = "/project/rating/%s" % project.id
......@@ -127,11 +127,10 @@ class ProductTemplate(models.Model):
return self.set_sequence_bottom()
@api.multi
def _website_url(self, field_name, arg):
res = super(ProductTemplate, self)._website_url(field_name, arg)
def _compute_website_url(self):
super(ProductTemplate, self)._compute_website_url()
for product in self:
res[product.id] = "/shop/product/%s" % (product.id,)
return res
product.website_url = "/shop/product/%s" % (product.id,)
@api.multi
def display_price(self, pricelist, qty=1, public=False, **kw):
......
......@@ -142,11 +142,11 @@ class Channel(models.Model):
@api.multi
@api.depends('name')
def _website_url(self, name, arg):
res = super(Channel, self)._website_url(name, arg)
def _compute_website_url(self):
super(Channel, self)._compute_website_url()
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
res.update({(channel.id, '%s/slides/%s' % (base_url, slug(channel))) for channel in self})
return res
for channel in self:
channel.website_url = '%s/slides/%s' % (base_url, slug(channel))
@api.onchange('visibility')
def change_visibility(self):
......@@ -346,17 +346,16 @@ class Slide(models.Model):
@api.multi
@api.depends('name')
def _website_url(self, name, arg):
res = super(Slide, self)._website_url(name, arg)
def _compute_website_url(self):
super(Slide, self)._compute_website_url()
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
#link_tracker is not in dependencies, so use it to shorten url only if installed.
if self.env.registry.get('link.tracker'):
LinkTracker = self.env['link.tracker']
res.update({(slide.id, LinkTracker.sudo().create({'url': '%s/slides/slide/%s' % (base_url, slug(slide))}).short_url) for slide in self})
else:
res.update({(slide.id, '%s/slides/slide/%s' % (base_url, slug(slide))) for slide in self})
return res
for slide in self:
#link_tracker is not in dependencies, so use it to shorten url only if installed.
if self.env.registry.get('link.tracker'):
url = self.env['link.tracker'].sudo().create({'url': '%s/slides/slide/%s' % (base_url, slug(slide))}).short_url
else:
url = '%s/slides/slide/%s' % (base_url, slug(slide))
slide.website_url = url
@api.model
def create(self, values):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment