# -*- coding: utf-8 -*- ############################################################################# # # Cybrosys Technologies Pvt. Ltd. # # Copyright (C) 2023-TODAY Cybrosys Technologies() # Author: Ahammed Harshad p() # # You can modify it under the terms of the GNU LESSER # GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. # # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE # (LGPL v3) along with this program. # If not, see . # ############################################################################# from odoo import fields, http from odoo.http import request from odoo.osv import expression from odoo.addons.website_blog.controllers.main import WebsiteBlog class WebsiteBlogInherit(WebsiteBlog): """Class inherit Website Blog to check recent posts""" @http.route([ '/blog', '/blog/page/', '/blog/tag/', '/blog/tag//page/', '''/blog/''', '''/blog//page/''', '''/blog//tag/''', '''/blog//tag//page/''', ], type='http', auth="public", website=True, sitemap=True) def blog(self, blog=None, tag=None, page=1, search=None, **opt): """Function recent posted blog @returns: Dict of the blog sorted by recent dates """ limit = 3 order = 'published_date desc' dom = expression.AND([ [('website_published', '=', True), ('post_date', '<=', fields.Datetime.now())], request.website.website_domain() ]) posts = request.env['blog.post'].search(dom, limit=limit, order=order) res = super(WebsiteBlogInherit, self).blog(blog=blog, tag=tag, page=1, search=search, **opt) res.qcontext.update({'posts_recent': posts}) return res @http.route([ '''/blog//''', ], type='http', auth="public", website=True, sitemap=True) def blog_post(self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **post): """Function recent posted blog posts @param blog_post: browse of the current post @param blog: browse of the current blog @param tag: current tag, if tag_id in parameters @param pager: a pager on the comments @returns Dictionary the blog posts sorted by recent dates """ limit = 3 order = 'published_date desc' dom = expression.AND([ [('website_published', '=', True), ('post_date', '<=', fields.Datetime.now())], request.website.website_domain() ]) posts = request.env['blog.post'].search(dom, limit=limit, order=order) res = super(WebsiteBlogInherit, self).blog_post(blog, blog_post, tag_id=tag_id, page=1, enable_editor=None, **post) res.qcontext.update({'posts_recent': posts}) return res