flectra/addons/website_livechat/controllers/main.py

43 lines
1.7 KiB
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
2018-01-16 11:34:37 +01:00
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
2018-01-16 11:34:37 +01:00
from flectra import http
from flectra.http import request
class WebsiteLivechat(http.Controller):
@http.route('/livechat/', type='http', auth="public", website=True)
def channel_list(self, **kw):
# display the list of the channel
channels = request.env['im_livechat.channel'].search([('website_published', '=', True)])
values = {
'channels': channels
}
return request.render('website_livechat.channel_list_page', values)
@http.route('/livechat/channel/<model("im_livechat.channel"):channel>', type='http', auth='public', website=True)
def channel_rating(self, channel, **kw):
# get the last 100 ratings and the repartition per grade
2018-07-13 11:51:12 +02:00
domain = [
('res_model', '=', 'mail.channel'), ('res_id', 'in', channel.sudo().channel_ids.ids),
('consumed', '=', True), ('rating', '>=', 1),
]
ratings = request.env['rating.rating'].search(domain, order='create_date desc', limit=100)
repartition = channel.sudo().channel_ids.rating_get_grades(domain=domain)
# compute percentage
percentage = dict.fromkeys(['great', 'okay', 'bad'], 0)
for grade in repartition:
2018-07-13 11:51:12 +02:00
percentage[grade] = round(repartition[grade] * 100.0 / sum(repartition.values()), 1) if sum(repartition.values()) else 0
# the value dict to render the template
values = {
'channel': channel,
'ratings': ratings,
'team': channel.sudo().user_ids,
'percentage': percentage
}
return request.render("website_livechat.channel_page", values)