Files
odoo_source/addons/website_rating/controllers/website_mail.py
T
Jérome Maes ccf869a83e [ADD] website_rating: generic rating management on chatter frontend
Extend new dynamic chatter to manage rating
when posting comment.

The model should inherit of rating.mixin and
its frontend chatter should allow rating to enjoy
star widget and rating card.

This is more generic : stats, rating, ... are manage
in one place (this module) for all document.
2017-06-30 11:07:00 +02:00

32 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug.exceptions import NotFound
from odoo import http
from odoo.http import request
from odoo.addons.website_mail.controllers.main import WebsiteMail
class WebsiteRating(WebsiteMail):
@http.route()
def website_chatter_init(self, res_model, res_id, domain=False, limit=False, **kwargs):
result = super(WebsiteRating, self).website_chatter_init(res_model, res_id, domain=domain, limit=limit, **kwargs)
# get the rating statistics about the record
if kwargs.get('rating_include'):
record = request.env[res_model].browse(res_id)
if hasattr(record, 'rating_get_stats'):
result['rating_stats'] = record.rating_get_stats([('website_published', '=', True)])
return result
@http.route()
def website_message_fetch(self, res_model, res_id, domain=False, limit=False, offset=False, **kw):
# add 'rating_include' in context, to fetch them in website_message_format
if kw.get('rating_include'):
context = dict(request.context)
context['rating_include'] = True
request.context = context
return super(WebsiteRating, self).website_message_fetch(res_model, res_id, domain=domain, limit=limit, offset=offset, **kw)