[MOV] website_slides: move slide.embed model into its own file

As we are going to do some rework on the slide.embed feature, let's put the
model into its own python file.

Task-2654009

Part-of: odoo/odoo#77736
This commit is contained in:
Aurélien Warnon
2021-11-24 10:18:17 +00:00
parent 6638b79c5e
commit 1a21b0896a
3 changed files with 32 additions and 24 deletions
+1
View File
@@ -5,6 +5,7 @@ from . import ir_http
from . import gamification_challenge
from . import slide_slide
from . import slide_question
from . import slide_embed
from . import slide_channel
from . import slide_channel_tag
from . import slide_slide_resource
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug import urls
from odoo import fields, models
class EmbeddedSlide(models.Model):
""" Embedding in third party websites. Track view count, generate statistics. """
_name = 'slide.embed'
_description = 'Embedded Slides View Counter'
_rec_name = 'slide_id'
slide_id = fields.Many2one('slide.slide', string="Presentation", required=True, index=True)
url = fields.Char('Third Party Website URL', required=True)
count_views = fields.Integer('# Views', default=1)
def _add_embed_url(self, slide_id, url):
baseurl = urls.url_parse(url).netloc
if not baseurl:
return 0
embeds = self.search([('url', '=', baseurl), ('slide_id', '=', int(slide_id))], limit=1)
if embeds:
embeds.count_views += 1
else:
embeds = self.create({
'slide_id': slide_id,
'url': baseurl,
})
return embeds.count_views
@@ -56,30 +56,6 @@ class SlidePartnerRelation(models.Model):
('partner_id', 'in', self.partner_id.ids),
])._recompute_completion()
class EmbeddedSlide(models.Model):
""" Embedding in third party websites. Track view count, generate statistics. """
_name = 'slide.embed'
_description = 'Embedded Slides View Counter'
_rec_name = 'slide_id'
slide_id = fields.Many2one('slide.slide', string="Presentation", required=True, index=True)
url = fields.Char('Third Party Website URL', required=True)
count_views = fields.Integer('# Views', default=1)
def _add_embed_url(self, slide_id, url):
baseurl = urls.url_parse(url).netloc
if not baseurl:
return 0
embeds = self.search([('url', '=', baseurl), ('slide_id', '=', int(slide_id))], limit=1)
if embeds:
embeds.count_views += 1
else:
embeds = self.create({
'slide_id': slide_id,
'url': baseurl,
})
return embeds.count_views
class SlideTag(models.Model):
""" Tag to search slides across channels. """