[IMP] website_livechat : make it depend on rating_livechat. It now propose to display livechat channel on website pages, with its ratings and description.

This commit is contained in:
Jérome Maes
2015-01-08 12:28:22 +01:00
parent ade60d54bb
commit abcb165d97
11 changed files with 236 additions and 19 deletions
+2 -1
View File
@@ -1 +1,2 @@
import models
import controllers
import models
+4 -1
View File
@@ -7,6 +7,7 @@
Odoo Website LiveChat
========================
For website built with Odoo CMS, this module include a chat button on your Website, and allow your visitors to chat with your collabarators.
It also will include the feedback tool for the livechat, and web pages to display your channel and its ratings on the website.
""",
'author': 'OpenERP SA',
'depends': ['website', 'im_livechat'],
@@ -14,6 +15,8 @@ For website built with Odoo CMS, this module include a chat button on your Websi
'data': [
'views/website_livechat.xml',
'views/res_config.xml',
'website_livechat_data.xml'
'views/website_livechat_view.xml',
'security/ir.model.access.csv',
'website_livechat_data.xml',
],
}
@@ -0,0 +1 @@
import main
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
from openerp import http
from openerp.http import request
class website_rating_livechat(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'].sudo().search([('website_published','=', True)])
values = {
'channels' : channels
}
return request.website.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):
# expose the ratings of the channel
if channel.website_published:
# get the last 100 ratings and the repartition per grade
ratings = request.env['rating.rating'].search([('res_model','=','im_chat.session'), ('res_id', 'in', channel.sudo().session_ids.ids)], order='create_date desc', limit=100)
repartition = channel.sudo().session_ids.rating_get_grades()
# compute percentage
percentage = dict.fromkeys(['great', 'okay', 'bad'], 0)
for grade in repartition:
percentage[grade] = repartition[grade] * 100 / sum(repartition.values()) 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.website.render("website_livechat.channel_page", values)
else:
return request.website.render('website.403')
+2 -1
View File
@@ -1 +1,2 @@
import website
import website
import im_livechat
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
from openerp import models, fields
class im_livechat_channel(models.Model):
_inherit = 'im_livechat.channel'
website_published = fields.Boolean("Website published", default=False, help="If checked, the channel and its ratings will be display on your website")
website_description = fields.Html("Website description", default=False, help="Description of the channel displayed on the website page")
+11 -9
View File
@@ -1,15 +1,17 @@
from openerp.osv import osv, fields
class website(osv.osv):
from openerp import fields, models
class website(models.Model):
_inherit = "website"
_columns = {
'channel_id': fields.many2one('im_livechat.channel', string="Channel"),
}
channel_id = fields.Many2one('im_livechat.channel', string='Live Chat Channel')
class website_config_settings(models.TransientModel):
class website_config_settings(osv.osv_memory):
_inherit = 'website.config.settings'
_columns = {
'channel_id': fields.related('website_id', 'channel_id', type='many2one', relation='im_livechat.channel', string='Live Chat Channel'),
}
channel_id = fields.Many2one('im_livechat.channel', string='Live Chat Channel', related='website_id.channel_id')
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_im_livechat_channel_public,im_livechat.channel.public,im_livechat.model_im_livechat_channel,base.group_public,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_im_livechat_channel_public im_livechat.channel.public im_livechat.model_im_livechat_channel base.group_public 1 0 0 0
@@ -2,13 +2,151 @@
<openerp>
<data>
<template id="header" inherit_id="website.layout" name="LiveChat Import (internal) Scripts">
<xpath expr="//body" position="inside">
<t t-if="website and website.channel_id">
<t t-raw="website.channel_id.script_internal"/>
</t>
</xpath>
</template>
<template id="header" inherit_id="website.layout" name="LiveChat Import (internal) Scripts">
<xpath expr="//body" position="inside">
<t t-if="website and website.channel_id">
<t t-raw="website.channel_id.script_internal"/>
</t>
</xpath>
</template>
<!-- Layout add footer -->
<template id="header_footer_custom" inherit_id="website.footer_default" name="Footer Rating Livechat Link">
<xpath expr="//ul[@id='products']" position="inside">
<li><a href="/livechat/">Livechat Support</a></li>
</xpath>
</template>
<!-- Page Layout -->
<template id="channel_page" name="Livechat Channel Satisfaction Page" page="True">
<t t-call="website.layout">
<div id="wrap">
<div class="container">
<h1><span>Livechat Channel</span> <small t-field="channel.name" /></h1>
<div t-field="channel.website_description" class="oe_structure mt16" />
<div class="row mt32">
<div class="col-md-8">
<t t-if="len(ratings) &gt; 0">
<div class="row">
<h3>Statistics</h3>
<div class="row">
<div class="col-md-3">
<div class="panel panel-warming">
<div class="panel-body text-center bg-warning">
<img src="/rating/static/src/img/rating_5.png" style="height:50px"/>
</div>
<div class="panel-body text-center bg-warning">
<h2 style="margin: 0">
<b style="font-size: 50px">
<t t-esc="percentage['okay']" />
</b>
<small>%</small>
</h2>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-success">
<div class="panel-body text-center bg-success">
<img src="/rating/static/src/img/rating_10.png" style="height:60px"/>
</div>
<div class="panel-body text-center bg-success">
<h2 style="margin: 0">
<b style="font-size: 60px">
<t t-esc="percentage['great']" />
</b>
<small>%</small>
</h2>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-danger">
<div class="panel-body text-center bg-danger">
<img src="/rating/static/src/img/rating_0.png" style="height:40px"/>
</div>
<div class="panel-body text-center bg-danger">
<h2 style="margin: 0">
<b style="font-size: 40px">
<t t-esc="percentage['bad']" />
</b>
<small>%</small>
</h2>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 mb32">
<h3>The <t t-esc="len(ratings)"/> last feedbacks</h3>
<div style="text-align:center">
<t t-foreach="ratings" t-as="rating" class="media">
<img t-attf-src='/rating/static/src/img/rating_#{int(rating.rating)}.png' t-att-alt="rating.res_name"/>
<t t-if="(rating_index+1) % 10 == 0">
<br/>
</t>
</t>
</div>
</div>
</div>
</t>
<t t-if="len(ratings) == 0">
<h4 style="text-align:center">This is no rating for this channel for now.</h4>
</t>
</div>
<div class="col-md-4 mb32">
<h3>The Team</h3>
<t t-foreach="team" t-as="user" class="media">
<div class="media">
<div class="pull-left">
<img t-att-src="'data:image/png;base64,' + user.image_small" class="img-rounded" t-att-alt="user.name"/>
</div>
<div class="media-body">
<h5><t t-esc="user.name"/></h5>
</div>
</div>
</t>
</div>
</div>
</div>
</div>
</t>
</template>
<template id="channel_list_page" name="Livechat Channel List Page">
<t t-call="website.layout">
<div id="wrap">
<div class="oe_structure"/>
<div class="container">
<h1>Livechat Support Channels</h1>
<div class="row mt32 mb32">
<t t-if="not len(channels)">
<div class="col-md-6 col-md-offset-3">
There is no public livechat channel to show.
</div>
</t>
<t t-if="len(channels)">
<div class="col-md-6 col-md-offset-3">
<t t-foreach="channels" t-as="channel">
<div class="media">
<a class="pull-left" t-attf-href="/livechat/channel/#{ slug(channel)}">
<img t-att-src="'data:image/png;base64,' + channel.image_small" t-att-alt="channel.name" />
</a>
<div class="media-body">
<h4 class="media-heading"><t t-esc="channel.name"/></h4>
</div>
</div>
</t>
</div>
</t>
</div>
</div>
<div class="oe_structure"/>
</div>
</t>
</template>
</data>
</openerp>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="im_livechat_channel_form_view" model="ir.ui.view">
<field name="name">im_livechat.channel.form.with.website_published</field>
<field name="model">im_livechat.channel</field>
<field name="inherit_id" ref="im_livechat.support_channel_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@string='Options']" position="inside">
<field name="website_published" widget="website_button"/>
</xpath>
</field>
</record>
</data>
</openerp>