[IMP] web, website_blog, website_forum, website_sale : uniformize the way to add comment by redirecting to login form (if not logged) and keep the parameters (i.e. the comment) when redirecting to the comment route. The comment route must now be GET and POST.

This commit is contained in:
Jérome Maes
2015-04-03 13:29:58 +02:00
parent d12bf0eb4a
commit 093e39bd17
5 changed files with 16 additions and 23 deletions
+4 -4
View File
@@ -311,12 +311,12 @@ def set_cookie_and_redirect(redirect_url):
def login_redirect():
url = '/web/login?'
if request.debug:
url += 'debug&'
# built the redirect url, keeping all the query parameters of the url
redirect_url = '%s?%s' % (request.httprequest.base_url, werkzeug.urls.url_encode(request.params))
return """<html><head><script>
window.location = '%sredirect=' + encodeURIComponent(window.location);
window.location = '%sredirect=' + encodeURIComponent("%s");
</script></head></html>
""" % (url,)
""" % (url, redirect_url)
def load_actions_from_ir_values(key, key2, models, meta):
Values = request.session.model('ir.values')
+7 -14
View File
@@ -2,13 +2,13 @@
import datetime
import json
import urllib
import werkzeug
from openerp import tools
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.models.website import slug, unslug
from openerp.addons.web.controllers.main import login_redirect
from openerp.exceptions import UserError
from openerp.osv.orm import browse_record
from openerp.tools.translate import _
@@ -271,22 +271,15 @@ class WebsiteBlog(http.Controller):
context=context)
return message_id
@http.route(['/blog/post_comment'], type='http', auth="public", methods=['GET', 'POST'], website=True)
@http.route(['/blog/post_comment/<int:blog_post_id>'], type='http', auth="public", website=True)
def blog_post_comment(self, blog_post_id=0, **kw):
if not request.session.uid:
return login_redirect()
cr, uid, context = request.cr, request.uid, request.context
redirect_url = request.httprequest.referrer + "#comments"
if kw.get('comment'):
if not request.session.uid: # if not logged, redirect to the login form, keeping the url to post the comment
kw['comment'] = kw.get('comment').encode('utf8') # avoid crash from urlencode if accent
url = '/blog/post_comment/?blog_post_id=%s&%s' % (blog_post_id, urllib.urlencode(kw))
redirect_url = '/web/login?redirect=%s' % urllib.quote(url)
else:
blog_post_id = int(blog_post_id)
blog_post = request.registry['blog.post']
post = blog_post.browse(cr, uid, blog_post_id, context=context)
self._blog_post_message(blog_post_id, kw.get('comment'), **kw)
redirect_url = "/blog/%s/post/%s#comments" % (slug(post.blog_id), slug(post))
return werkzeug.utils.redirect(redirect_url)
self._blog_post_message(blog_post_id, kw.get('comment'), **kw)
blog_post = request.registry['blog.post'].browse(cr, uid, blog_post_id, context=context)
return werkzeug.utils.redirect("/blog/%s/post/%s#comments" % (slug(blog_post.blog_id), slug(blog_post)))
def _get_discussion_detail(self, ids, publish=False, **post):
@@ -294,7 +294,7 @@
</xpath>
<xpath expr="//ul[@id='comments-list']" position="before">
<section class="mb32 read_width css_editable_mode_hidden">
<form id="comment" t-attf-action="/blog/post_comment" method="POST">
<form id="comment" t-attf-action="/blog/post_comment/#{blog_post.id}" method="POST">
<div class="media">
<span class="pull-left">
<img t-if="user_id.partner_id.image_small" class="img img-circle media-object" t-att-src="website.image_url(user_id.partner_id, 'image_small')" style="width: 30px"/>
+2 -2
View File
@@ -313,7 +313,7 @@ class WebsiteForum(http.Controller):
@http.route(['/forum/<model("forum.forum"):forum>/new',
'/forum/<model("forum.forum"):forum>/<model("forum.post"):post_parent>/reply'],
type='http', auth="public", methods=['POST'], website=True)
type='http', auth="public", website=True)
def post_create(self, forum, post_parent=None, post_type=None, **post):
if not request.session.uid:
return login_redirect()
@@ -329,7 +329,7 @@ class WebsiteForum(http.Controller):
})
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), post_parent and slug(post_parent) or new_question.id))
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment', type='http', auth="public", methods=['POST'], website=True)
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment', type='http', auth="public", website=True)
def post_comment(self, forum, post, **kwargs):
if not request.session.uid:
return login_redirect()
+2 -2
View File
@@ -289,7 +289,7 @@ class website_sale(http.Controller):
}
return request.website.render("website_sale.product", values)
@http.route(['/shop/product/comment/<int:product_template_id>'], type='http', auth="public", methods=['POST'], website=True)
@http.route(['/shop/product/comment/<int:product_template_id>'], type='http', auth="public", website=True)
def product_comment(self, product_template_id, **post):
if not request.session.uid:
return login_redirect()
@@ -301,7 +301,7 @@ class website_sale(http.Controller):
type='comment',
subtype='mt_comment',
context=dict(context, mail_create_nosubscribe=True))
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
return werkzeug.utils.redirect('/shop/product/%s#comments' % product_template_id)
@http.route(['/shop/pricelist'], type='http', auth="public", website=True)
def pricelist(self, promo, **post):