[IMP][REF] website_blog, website_event, website_event_track,

website_hr_recruitment, website_sale: add published mixin on blog / event /
track / job / product objects and update their website url and form view
according to the publish mixin/button refactoring.
This commit is contained in:
David Monjoie
2015-01-20 17:34:33 +01:00
committed by Thibault Delavallée
parent b84721cb21
commit 04e412ccb8
10 changed files with 60 additions and 54 deletions
+6 -7
View File
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import difflib
import lxml
import random
@@ -65,11 +64,15 @@ class BlogTag(osv.Model):
class BlogPost(osv.Model):
_name = "blog.post"
_description = "Blog Post"
_inherit = ['mail.thread', 'website.seo.metadata']
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.mixin']
_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
def _compute_ranking(self, cr, uid, ids, name, arg, context=None):
res = {}
@@ -91,10 +94,6 @@ class BlogPost(osv.Model):
'blog.tag', string='Tags',
),
'content': fields.html('Content', translate=True, sanitize=False),
# website control
'website_published': fields.boolean(
'Publish', help="Publish on the website", copy=False,
),
'website_message_ids': fields.one2many(
'mail.message', 'res_id',
domain=lambda self: [
@@ -53,6 +53,12 @@
<field name="arch" type="xml">
<form string="Blog Post">
<sheet>
<div class="oe_right oe_button_box">
<button class="oe_inline oe_stat_button" name="open_website_url"
type="object" icon="fa-globe">
<field name="website_published" widget="website_button"/>
</button>
</div>
<group>
<field name="name" placeholder="Name"/>
<field name="tag_ids" widget="many2many_tags"/>
+6 -9
View File
@@ -14,7 +14,7 @@ from openerp.addons.website.models.website import slug
class event(models.Model):
_name = 'event.event'
_inherit = ['event.event', 'website.seo.metadata']
_inherit = ['event.event', 'website.seo.metadata', 'website.published.mixin']
_track = {
'website_published': {
'website_event.mt_event_published': lambda self, cr, uid, obj, ctx=None: obj.website_published,
@@ -23,7 +23,6 @@ class event(models.Model):
}
twitter_hashtag = fields.Char('Twitter Hashtag', default=lambda self: self._default_hashtag())
website_published = fields.Boolean('Visible in Website', copy=False)
# TDE TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
website_message_ids = fields.One2many(
'mail.message', 'res_id',
@@ -33,15 +32,13 @@ class event(models.Model):
string='Website Messages',
help="Website communication history",
)
website_url = fields.Char('Website url', compute='_website_url')
@api.one
@api.multi
@api.depends('name')
def _website_url(self):
if isinstance(self.id, NewId):
self.website_url = ''
else:
self.website_url = "/event/" + slug(self)
def _website_url(self, name, arg):
res = super(event, self)._website_url(name, arg)
res.update({(e.id, '/event/%s' % slug(e)) for e in self})
return res
def _default_hashtag(self):
return re.sub("[- \\.\\(\\)\\@\\#\\&]+", "", self.env.user.company_id.name).lower()
@@ -8,9 +8,12 @@
<field name="inherit_id" ref="event.view_event_form"/>
<field name="arch" type="xml">
<!-- add state field in header -->
<xpath expr="//div[@class='oe_right oe_button_box']" position="before">
<xpath expr="//div[@class='oe_right oe_button_box']" position="inside">
<field name="website_url" invisible="1"/>
<field name="website_published" class="pull-right" widget="website_button"/>
<button class="oe_inline oe_stat_button" name="open_website_url"
type="object" icon="fa-globe">
<field name="website_published" widget="website_button"/>
</button>
</xpath>
<xpath expr="//field[@name='organizer_id']" position="after">
<field name="twitter_hashtag"/>
+8 -7
View File
@@ -25,11 +25,7 @@ class event_track(models.Model):
_name = "event.track"
_description = 'Event Tracks'
_order = 'priority, date'
_inherit = ['mail.thread', 'ir.needaction_mixin', 'website.seo.metadata']
@api.one
def _compute_website_url(self):
self.website_url = "/event/%s/track/%s" % (slug(self.event_id), slug(self))
_inherit = ['mail.thread', 'ir.needaction_mixin', 'website.seo.metadata', 'website.published.mixin']
name = fields.Char('Title', required=True, translate=True)
@@ -49,8 +45,6 @@ class event_track(models.Model):
('0', 'Low'), ('1', 'Medium'),
('2', 'High'), ('3', 'Highest')],
'Priority', required=True, default='1')
website_published = fields.Boolean('Available in the website', copy=False)
website_url = fields.Char("Website url", compute='_compute_website_url')
image = fields.Binary('Image', compute='_compute_image', readonly=True, store=True)
@api.one
@@ -61,6 +55,13 @@ class event_track(models.Model):
else:
self.image = False
@api.multi
@api.depends('name')
def _website_url(self, field_name, arg):
res = super(event_track, self)._website_url(field_name, arg)
res.update({(track.id, '/event/%strack/%s' % (slug(track.event_id), slug(track))) for track in self})
return res
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):
""" Override read_group to always display all states. """
if groupby and groupby[0] == "state":
@@ -90,7 +90,10 @@
<sheet string="Track">
<div class="oe_right oe_button_box">
<field name="website_url" invisible="1"/>
<field name="website_published" class="pull-right" widget="website_button"/>
<button class="oe_inline oe_stat_button" name="open_website_url"
type="object" icon="fa-globe">
<field name="website_published" widget="website_button"/>
</button>
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
@@ -2,12 +2,13 @@
from openerp.osv import osv, fields
class hr_job(osv.osv):
_name = 'hr.job'
_inherit = ['hr.job','website.seo.metadata']
_inherit = ['hr.job', 'website.seo.metadata', 'website.published.mixin']
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, '')
res = super(hr_job, self)._website_url(cr, uid, ids, field_name, arg, context=context)
for job in self.browse(cr, uid, ids, context=context):
res[job.id] = "/jobs/detail/%s" % job.id
return res
@@ -17,10 +18,5 @@ class hr_job(osv.osv):
return super(hr_job, self).job_open(cr, uid, ids, context)
_columns = {
'website_published': fields.boolean('Published', copy=False),
'website_description': fields.html('Website description'),
'website_url': fields.function(_website_url, string="Website URL", type="char"),
}
_defaults = {
'website_published': False
}
@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_hr_job_form" model="ir.ui.view">
<field name="name">hr.job.form.inherit</field>
<record id="view_hr_job_form_website_published_button" model="ir.ui.view" >
<field name="name">hr.job.form.inherit.published.button</field>
<field name="model">hr.job</field>
<field name="inherit_id" ref="hr.view_hr_job_form"/>
<field name="inherit_id" ref="hr_recruitment.hr_job_survey"/>
<field name="arch" type="xml">
<!-- add state field in header -->
<xpath expr="//sheet/div" position="before">
<field name="website_url" invisible="1"/>
<field name="website_published" class="pull-right" widget="website_button"/>
<xpath expr="//div[@class='oe_button_box']" position="inside">
<button class="oe_inline oe_stat_button" name="open_website_url"
type="object" icon="fa-globe">
<field name="website_published" widget="website_button"/>
</button>
</xpath>
</field>
</record>
+8 -13
View File
@@ -102,13 +102,13 @@ class product_public_category(osv.osv):
}
class product_template(osv.Model):
_inherit = ["product.template", "website.seo.metadata"]
_inherit = ["product.template", "website.seo.metadata", 'website.published.mixin']
_order = 'website_published desc, website_sequence desc, name'
_name = 'product.template'
_mail_post_access = 'read'
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, '')
res = super(product_template, self)._website_url(cr, uid, ids, field_name, arg, context=context)
for product in self.browse(cr, uid, ids, context=context):
res[product.id] = "/shop/product/%s" % (product.id,)
return res
@@ -122,7 +122,6 @@ class product_template(osv.Model):
],
string='Website Comments',
),
'website_published': fields.boolean('Available in the website', copy=False),
'website_description': fields.html('Description for the website', translate=True),
'alternative_product_ids': fields.many2many('product.template','product_alternative_rel','src_id','dest_id', string='Alternative Products', help='Appear on the product page'),
'accessory_product_ids': fields.many2many('product.product','product_accessory_rel','src_id','dest_id', string='Accessory Products', help='Appear on the shopping cart'),
@@ -130,7 +129,6 @@ class product_template(osv.Model):
'website_size_y': fields.integer('Size Y'),
'website_style_ids': fields.many2many('product.style', string='Styles'),
'website_sequence': fields.integer('Sequence', help="Determine the display order in the Website E-commerce"),
'website_url': fields.function(_website_url, string="Website url", type="char"),
'public_categ_ids': fields.many2many('product.public.category', string='Public Category', help="Those categories are used to group similar products for e-commerce."),
}
@@ -143,7 +141,6 @@ class product_template(osv.Model):
'website_size_x': 1,
'website_size_y': 1,
'website_sequence': _defaults_website_sequence,
'website_published': False,
}
def set_sequence_top(self, cr, uid, ids, context=None):
@@ -178,18 +175,15 @@ class product_template(osv.Model):
else:
return self.set_sequence_bottom(cr, uid, ids, context=context)
class product_product(osv.Model):
_inherit = "product.product"
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for product in self.browse(cr, uid, ids, context=context):
res[product.id] = "/shop/product/%s" % (product.product_tmpl_id.id,)
return res
# Wrapper for call_kw with inherits
def open_website_url(self, cr, uid, ids, context=None):
template_ids = list(set(self.browse(cr, uid, ids, context=context).product_tmpl_id.id))
return self.pool['product.template'].open_website_url(cr, uid, template_ids, context=context)
_columns = {
'website_url': fields.function(_website_url, string="Website url", type="char"),
}
class product_attribute(osv.Model):
_inherit = "product.attribute"
@@ -200,6 +194,7 @@ class product_attribute(osv.Model):
'type': lambda *a: 'radio',
}
class product_attribute_value(osv.Model):
_inherit = "product.attribute.value"
_columns = {
+6 -1
View File
@@ -23,13 +23,18 @@
<group name="website" string="Website">
<field name="website_url" invisible="1"/>
<field name="public_categ_ids" widget="many2many_tags"/>
<field name="website_published" class="pull-right" widget="website_button"/>
<field name="alternative_product_ids" widget="many2many_tags"/>
<field name="accessory_product_ids" widget="many2many_tags"/>
<field name="website_style_ids" widget="many2many_tags"/>
<field name="website_sequence"/>
</group>
</group>
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" name="open_website_url"
type="object" icon="fa-globe">
<field name="website_published" widget="website_button"/>
</button>
</xpath>
</field>
</record>