Skip to content
Snippets Groups Projects
Commit 4eb2aeb8 authored by Romain Derie's avatar Romain Derie
Browse files

[IMP] website: make cover_properties a mixin field

Next commit will add new cover properties entries for the bg color.
Still, we want a default `bg-primary` class. Instead of addind 3 new default
value in existing cover_property fields, the chance is taken to make a mixin
out of that field to avoid code duplication.

task-2144335
parent 8fc61fd2
Branches
Tags
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import logging
......@@ -97,6 +98,21 @@ class SeoMetadata(models.AbstractModel):
}
class WebsiteCoverPropertiesMixin(models.AbstractModel):
_name = 'website.cover_properties.mixin'
_description = 'Cover Properties Website Mixin'
cover_properties = fields.Text('Cover Properties', default=lambda s: json.dumps(s._default_cover_properties()))
def _default_cover_properties(self):
return {
"background-image": "none",
"opacity": "0.2",
"resize_class": "o_half_screen_height",
}
class WebsiteMultiMixin(models.AbstractModel):
_name = 'website.multi.mixin'
......
......@@ -14,16 +14,13 @@ from odoo.tools import html2plaintext
class Blog(models.Model):
_name = 'blog.blog'
_description = 'Blog'
_inherit = ['mail.thread', 'website.seo.metadata', 'website.multi.mixin']
_inherit = ['mail.thread', 'website.seo.metadata', 'website.multi.mixin', 'website.cover_properties.mixin']
_order = 'name'
name = fields.Char('Blog Name', required=True, translate=True)
subtitle = fields.Char('Blog Subtitle', translate=True)
active = fields.Boolean('Active', default=True)
content = fields.Html('Content', translate=html_translate, sanitize=False)
cover_properties = fields.Text(
'Cover Properties',
default='{"background-image": "none", "opacity": "0.2", "resize_class": "o_half_screen_height"}')
def write(self, vals):
res = super(Blog, self).write(vals)
......@@ -114,7 +111,7 @@ class BlogTag(models.Model):
class BlogPost(models.Model):
_name = "blog.post"
_description = "Blog Post"
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.multi.mixin']
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.multi.mixin', 'website.cover_properties.mixin']
_order = 'id DESC'
_mail_post_access = 'read'
......@@ -131,9 +128,6 @@ class BlogPost(models.Model):
subtitle = fields.Char('Sub Title', translate=True)
author_id = fields.Many2one('res.partner', 'Author', default=lambda self: self.env.user.partner_id)
active = fields.Boolean('Active', default=True)
cover_properties = fields.Text(
'Cover Properties',
default='{"background-image": "none", "opacity": "0.2", "resize_class": "o_half_screen_height"}')
blog_id = fields.Many2one('blog.blog', 'Blog', required=True, ondelete='cascade')
tag_ids = fields.Many2many('blog.tag', string='Tags')
content = fields.Html('Content', default=_default_content, translate=html_translate, sanitize=False)
......
......@@ -19,7 +19,7 @@ class EventType(models.Model):
class Event(models.Model):
_name = 'event.event'
_inherit = ['event.event', 'website.seo.metadata', 'website.published.multi.mixin']
_inherit = ['event.event', 'website.seo.metadata', 'website.published.multi.mixin', 'website.cover_properties.mixin']
# description
subtitle = fields.Char('Event Subtitle', translate=True)
......@@ -27,9 +27,6 @@ class Event(models.Model):
is_participating = fields.Boolean("Is Participating", compute="_compute_is_participating")
# website
website_published = fields.Boolean(tracking=True)
cover_properties = fields.Text(
'Cover Properties',
default='{"background-image": "none", "opacity": "0.4", "resize_class": "o_half_screen_height"}')
website_menu = fields.Boolean(
'Dedicated Menu', copy=False,
help="Creates menus Introduction, Location and Register on the page "
......@@ -59,6 +56,11 @@ class Event(models.Model):
if self.event_type_id:
self.website_menu = self.event_type_id.website_menu
def _default_cover_properties(self):
res = super()._default_cover_properties()
res['opacity'] = '0.4'
return res
def _get_menu_entries(self):
""" Method returning menu entries to display on the website view of the
event, possibly depending on some options in inheriting modules. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment