[IMP] website_*: adapt website modules using frontend chatter

This commit is contained in:
Jérome Maes
2017-06-30 11:07:00 +02:00
parent ccf869a83e
commit 0339264d11
10 changed files with 15 additions and 120 deletions
@@ -299,13 +299,11 @@
</template>
<!-- Options: Blog Post: user can reply -->
<template id="opt_blog_post_complete_comment" name="Allow blog post comment"
inherit_id="website_blog.blog_post_complete" active="False" customize_show="True">
<template id="opt_blog_post_complete_comment" name="Allow blog post comment" inherit_id="website_blog.blog_post_complete" active="False" customize_show="True">
<xpath expr="//div[@class='o_blog_post_complete o_sharing_links']" position="after">
<section id="comments" class="read_width">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="blog_post"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</section>
</xpath>
@@ -517,7 +517,6 @@
<div class="col-md-10 col-md-offset-1 mt16">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="lead"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</div>
</div>
@@ -800,7 +799,6 @@
<div class="col-md-10 col-md-offset-1 mt16">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="opportunity"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</div>
</div>
@@ -134,7 +134,6 @@
<div class="col-md-10 col-md-offset-1 mt16">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="project"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</div>
</div>
@@ -254,7 +253,6 @@
<div class="col-md-10 col-md-offset-1 mt16">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="task"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</div>
</div>
@@ -136,7 +136,6 @@
<div class="col-md-10 col-md-offset-1 mt16">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="issue"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</div>
</div>
@@ -443,7 +443,6 @@
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="quotation"/>
<t t-set="token_field" t-value="'access_token'"/>
<t t-set="chatter_mode" t-value="'json'"/>
</t>
</xpath>
<xpath expr="//a[@data-target='#modaldecline']" position="before">
+1 -1
View File
@@ -10,7 +10,7 @@ Odoo E-Commerce
==================
""",
'depends': ['website', 'sale', 'payment', 'website_payment', 'website_portal_sale', 'website_account', 'website_mail', 'website_form', 'rating'],
'depends': ['website', 'sale', 'payment', 'website_payment', 'website_portal_sale', 'website_account', 'website_mail', 'website_form', 'website_rating'],
'data': [
'security/ir.model.access.csv',
'security/website_sale.xml',
+1 -1
View File
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import backend
from . import main
from . import website_mail
-8
View File
@@ -277,7 +277,6 @@ class WebsiteSale(http.Controller):
def product(self, product, category='', search='', **kwargs):
product_context = dict(request.env.context, active_id=product.id)
ProductCategory = request.env['product.public.category']
Rating = request.env['rating.rating']
if category:
category = ProductCategory.browse(int(category)).exists()
@@ -296,11 +295,6 @@ class WebsiteSale(http.Controller):
to_currency = pricelist.currency_id
compute_currency = lambda price: from_currency.compute(price, to_currency)
# get the rating attached to a mail.message, and the rating stats of the product
ratings = Rating.search([('message_id', 'in', product.website_message_ids.ids)])
rating_message_values = dict([(record.message_id.id, record.rating) for record in ratings])
rating_product = product.rating_get_stats([('website_published', '=', True)])
if not product_context.get('pricelist'):
product_context['pricelist'] = pricelist.id
product = product.with_context(product_context)
@@ -317,8 +311,6 @@ class WebsiteSale(http.Controller):
'main_object': product,
'product': product,
'get_attribute_value_ids': self.get_attribute_value_ids,
'rating_message_values': rating_message_values,
'rating_product': rating_product
}
return request.render("website_sale.product", values)
@@ -1,52 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug import urls
from odoo import http
from odoo.http import request
from odoo.addons.website_mail.controllers.main import WebsiteMail
class WebsiteMailController(WebsiteMail):
@http.route(['/website_mail/post/json'], type='json', auth='public', website=True)
def chatter_json(self, res_model='', res_id=None, message='', **kw):
params = kw.copy()
params.pop('rating', False)
message_data = super(WebsiteMailController, self).chatter_json(res_model=res_model, res_id=res_id, message=message, **params)
if message_data and kw.get('rating') and res_model == 'product.template': # restrict rating only for product template
res_model_id = request.env.ref('product.model_product_template').id
rating = request.env['rating.rating'].create({
'rating': float(kw.get('rating')),
'res_model_id': res_model_id,
'res_id': res_id,
'message_id': message_data['id'],
'consumed': True,
})
message_data.update({
'rating_default_value': rating.rating,
'rating_disabled': True,
})
return message_data
@http.route(['/website_mail/post/post'], type='http', methods=['POST'], auth='public', website=True)
def chatter_post(self, res_model='', res_id=None, message='', redirect=None, **kw):
params = kw.copy()
params.pop('rating')
response = super(WebsiteMailController, self).chatter_post(res_model=res_model, res_id=res_id, message=message, redirect=redirect, **params)
if kw.get('rating') and res_model == 'product.template': # restrict rating only for product template
try:
fragment = urls.url_parse(response.location).fragment
message_id = int(fragment.replace('message-', ''))
res_model_id = request.env.ref('product.model_product_template').id
request.env['rating.rating'].create({
'rating': float(kw.get('rating')),
'res_model_id': res_model_id,
'res_id': res_id,
'message_id': message_id,
'consumed': True,
})
except Exception:
pass
return response
+12 -49
View File
@@ -17,7 +17,6 @@
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_payment.js"></script>
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_validate.js"></script>
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_tour_buy.js"></script>
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_rating.js"></script>
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_tracking.js"></script>
</xpath>
</template>
@@ -552,32 +551,20 @@
<!-- Product options: OpenChatter -->
<template id="product_comment" inherit_id="website_sale.product" active="False" customize_show="True" name="Discussion and Rating">
<xpath expr="//div[@id='product_details']" position="inside">
<t t-call="rating.rating_card">
<t t-set="rating_stat" t-value="rating_product"/>
<t t-set="max_rate" t-value="5"/>
<t t-set="min_rate" t-value="1"/>
</t>
</xpath>
<xpath expr="//div[@t-field='product.website_description']" position="after">
<hr class="mb32"/>
<section class="container">
<div class="row col-md-10 col-md-offset-1">
<div class="text-muted">
<h3 class="fa fa-comment-o">
<a id="comments">
<t t-if="len(product.website_message_ids) &lt;= 1" ><t t-esc="len(product.website_message_ids)"/> comment</t>
<t t-if="len(product.website_message_ids) > 1"><t t-esc="len(product.website_message_ids)"/> comments</t>
</a>
</h3>
<div class="o_shop_discussion_rating">
<section class="container mt16 mb16">
<hr/>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="product"/>
<t t-set="display_rating" t-value="True"/>
</t>
</div>
</div>
<t t-call="website_mail.message_thread">
<t t-set="object" t-value="product"/>
<t t-set="chatter_mode" t-value="'json'"/>
<t t-set="rating_enable" t-value="True"/>
</t>
</div>
</section>
</section>
</div>
</xpath>
</template>
@@ -704,30 +691,6 @@
</ul>
</template>
<!-- extend the generic mail thread message template to add rating widget -->
<template id="message_thread_rating" inherit_id="website_mail.message_thread" name="Chatter with rating">
<xpath expr="//section[contains(@class, 'o_website_mail_thread')]" position="attributes">
<attribute name="t-att-data-rating-enabled">rating_message_values and 1 or 0</attribute>
</xpath>
<xpath expr="//textarea[@name='message']" position="before">
<t t-if="rating_enable">
<t t-call="rating.rating_star_card">
<t t-set="rating_input_name" t-value="'rating'" />
</t>
</t>
</xpath>
<xpath expr="//ul[contains(@class, 'o_website_comments')]//h5" position="after">
<t t-if="rating_enable">
<div t-if="rating_message_values.get(message.id)">
<t t-call="rating.rating_star_card">
<t t-set="rating_default_value" t-value="rating_message_values.get(message.id)" />
<t t-set="rating_disabled" t-value="True" />
</t>
</div>
</t>
</xpath>
</template>
<template id="wizard_checkout" name="Wizard Checkout">
<ul class="wizard pull-right hidden-xs">
<li t-att-class="step==10 and 'text-primary' or 'text-muted'" id="step10">