[IMP] website_slides compatible with Multi-Website
This commit is contained in:
parent
75b104de5b
commit
a8637343a9
@ -51,6 +51,7 @@ class Channel(models.Model):
|
||||
@api.depends('custom_slide_id', 'promote_strategy', 'slide_ids.likes',
|
||||
'slide_ids.total_views', "slide_ids.date_published")
|
||||
def _compute_promoted_slide_id(self):
|
||||
domain = self.env['website'].get_current_website()
|
||||
for record in self:
|
||||
if record.promote_strategy == 'none':
|
||||
record.promoted_slide_id = False
|
||||
@ -58,7 +59,7 @@ class Channel(models.Model):
|
||||
record.promoted_slide_id = record.custom_slide_id
|
||||
elif record.promote_strategy:
|
||||
slides = self.env['slide.slide'].search(
|
||||
[('website_published', '=', True), ('channel_id', '=', record.id)],
|
||||
[('website_published', '=', True), '|', ('website_ids', '=', False), ('website_ids', 'in', domain.id), ('channel_id', '=', record.id)],
|
||||
limit=1, order=self._order_by_strategy[record.promote_strategy])
|
||||
record.promoted_slide_id = slides and slides[0] or False
|
||||
|
||||
@ -71,8 +72,9 @@ class Channel(models.Model):
|
||||
@api.depends('slide_ids.slide_type', 'slide_ids.website_published')
|
||||
def _count_presentations(self):
|
||||
result = dict.fromkeys(self.ids, dict())
|
||||
domain = self.env['website'].get_current_website()
|
||||
res = self.env['slide.slide'].read_group(
|
||||
[('website_published', '=', True), ('channel_id', 'in', self.ids)],
|
||||
[('website_published', '=', True), '|', ('website_ids', '=', False), ('website_ids', 'in', domain.id), ('channel_id', 'in', self.ids)],
|
||||
['channel_id', 'slide_type'], ['channel_id', 'slide_type'],
|
||||
lazy=False)
|
||||
for res_group in res:
|
||||
@ -112,6 +114,11 @@ class Channel(models.Model):
|
||||
can_see_full = fields.Boolean('Full Access', compute='_compute_access')
|
||||
can_upload = fields.Boolean('Can Upload', compute='_compute_access')
|
||||
|
||||
website_ids = fields.Many2many('website', 'website_slide_channel_pub_rel',
|
||||
'website_id', 'slide_channel_id',
|
||||
string='Websites', copy=False,
|
||||
help='List of websites in which Slide channel is published.')
|
||||
|
||||
def _search_can_see(self, operator, value):
|
||||
if operator not in ('=', '!=', '<>'):
|
||||
raise ValueError('Invalid operator: %s' % (operator,))
|
||||
@ -200,8 +207,9 @@ class Category(models.Model):
|
||||
@api.depends('slide_ids.slide_type', 'slide_ids.website_published')
|
||||
def _count_presentations(self):
|
||||
result = dict.fromkeys(self.ids, dict())
|
||||
domain = self.env['website'].get_current_website()
|
||||
res = self.env['slide.slide'].read_group(
|
||||
[('website_published', '=', True), ('category_id', 'in', self.ids)],
|
||||
[('website_published', '=', True), '|', ('website_ids', '=', False), ('website_ids', 'in', domain.id), ('category_id', 'in', self.ids)],
|
||||
['category_id', 'slide_type'], ['category_id', 'slide_type'],
|
||||
lazy=False)
|
||||
for res_group in res:
|
||||
@ -288,6 +296,9 @@ class Slide(models.Model):
|
||||
image = fields.Binary('Image', attachment=True)
|
||||
image_medium = fields.Binary('Medium', compute="_get_image", store=True, attachment=True)
|
||||
image_thumb = fields.Binary('Thumbnail', compute="_get_image", store=True, attachment=True)
|
||||
website_ids = fields.Many2many('website', 'website_slide_pub_rel', 'website_id', 'slide_id',
|
||||
string='Websites', copy=False,
|
||||
help='List of websites in which Slide is published.')
|
||||
|
||||
@api.depends('image')
|
||||
def _get_image(self):
|
||||
@ -464,14 +475,16 @@ class Slide(models.Model):
|
||||
return groups
|
||||
|
||||
def get_related_slides(self, limit=20):
|
||||
domain = [('website_published', '=', True), ('channel_id.visibility', '!=', 'private'), ('id', '!=', self.id)]
|
||||
domain = self.env['website'].get_current_website()
|
||||
domain = [('website_published', '=', True), '|', ('website_ids', '=', False), ('website_ids', 'in', domain.id), ('channel_id.visibility', '!=', 'private'), ('id', '!=', self.id)]
|
||||
if self.category_id:
|
||||
domain += [('category_id', '=', self.category_id.id)]
|
||||
for record in self.search(domain, limit=limit):
|
||||
yield record
|
||||
|
||||
def get_most_viewed_slides(self, limit=20):
|
||||
for record in self.search([('website_published', '=', True), ('channel_id.visibility', '!=', 'private'), ('id', '!=', self.id)], limit=limit, order='total_views desc'):
|
||||
domain = self.env['website'].get_current_website()
|
||||
for record in self.search([('website_published', '=', True), '|', ('website_ids', '=', False), ('website_ids', 'in', domain.id), ('channel_id.visibility', '!=', 'private'), ('id', '!=', self.id)], limit=limit, order='total_views desc'):
|
||||
yield record
|
||||
|
||||
def _post_publication(self):
|
||||
|
@ -39,7 +39,7 @@
|
||||
<div class="row">
|
||||
<t t-foreach="channels" t-as="channel">
|
||||
<div t-if="channel_index % 3 == 0" class="clearfix"/>
|
||||
<div class="col-sm-4 mb32">
|
||||
<div class="col-sm-4 mb32" t-attf-data-publish="#{channel.website_published & (not channel.website_ids or website in channel.website_ids) and 'on' or 'off'}">
|
||||
<div class="well well-sm">
|
||||
<div>
|
||||
<a t-attf-href="/slides/#{slug(channel)}">
|
||||
|
@ -67,6 +67,7 @@
|
||||
<field name="channel_id"/>
|
||||
<field name="category_id" context="{'default_channel_id': channel_id}"/>
|
||||
<field name="website_url"/>
|
||||
<field name="website_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Description">
|
||||
@ -230,6 +231,7 @@
|
||||
<field name="promote_strategy" widget="radio"/>
|
||||
<field name="custom_slide_id" class="oe_edit_only" attrs="{'invisible': [('promote_strategy', '!=', 'custom')]}" domain="[('channel_id','=',id), ('website_published','=',True)]"/>
|
||||
<field name="promoted_slide_id" attrs="{'invisible': [('promote_strategy', '!=', 'custom')]}"/>
|
||||
<field name="website_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="publish_template_id" domain="[('model','=','slide.slide')]"/>
|
||||
|
Loading…
Reference in New Issue
Block a user