In Python 3: * various builtins and dict methods were changed to return view/iterable objects rather than lists * and the separate Python 2 view/iterable builtins and methods were removed altogether This is problematic when using these items as list (which the happens repeatedly in Odoo), but more viciously when iterating *multiple times* over them (which also happens, which I've messed up multiple times while writing this, and which is a pain to debug even when you've just created the issue). Convert all code using these to semantics-matching cross-version helper functions to get the LCD behaviour between P2 and P3, and forbid the builtins via lint. issue #8530
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.tools import pycompat
|
|
|
|
|
|
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
|
|
ratings = request.env['rating.rating'].search([('res_model', '=', 'mail.channel'), ('res_id', 'in', channel.sudo().channel_ids.ids)], order='create_date desc', limit=100)
|
|
repartition = channel.sudo().channel_ids.rating_get_grades()
|
|
|
|
# compute percentage
|
|
percentage = dict.fromkeys(['great', 'okay', 'bad'], 0)
|
|
for grade in repartition:
|
|
percentage[grade] = repartition[grade] * 100 / sum(pycompat.values(repartition)) if sum(pycompat.values(repartition)) 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)
|