[IMP] website: public_uid
bzr revid: chm@openerp.com-20130801143347-ihg8nkb1frs08rl2
This commit is contained in:
@@ -8,6 +8,7 @@ from openerp.addons.web.http import request
|
||||
|
||||
def auth_method_public():
|
||||
registry = openerp.modules.registry.RegistryManager.get(request.db)
|
||||
request.public_uid = None
|
||||
with registry.cursor() as cr:
|
||||
request.public_uid = request.registry['ir.model.data'].get_object_reference(cr, openerp.SUPERUSER_ID, 'website', 'public_user')[1]
|
||||
if not request.session.uid:
|
||||
@@ -30,6 +31,7 @@ class website(object):
|
||||
'script': script,
|
||||
'css': css,
|
||||
'host_url': request.httprequest.host_url,
|
||||
'res_company': request.registry['res.company'].browse(request.cr, openerp.SUPERUSER_ID, 1),
|
||||
}
|
||||
_values.update(add_values)
|
||||
return request.registry.get("ir.ui.view").render(request.cr, request.uid, template, _values)
|
||||
|
||||
@@ -12,7 +12,6 @@ class website_hr(http.Controller):
|
||||
|
||||
employee_ids = hr_obj.search(request.cr, request.uid, [(1, "=", 1)])
|
||||
values = {
|
||||
'res_company': request.registry['res.company'].browse(request.cr, request.uid, 1),
|
||||
'employee_ids': hr_obj.browse(request.cr, request.uid, employee_ids),
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ class website_mail(http.Controller):
|
||||
message_obj = request.registry['mail.message']
|
||||
|
||||
values = {
|
||||
'res_company': request.registry['res.company'].browse(request.cr, request.uid, 1),
|
||||
'blog_ids': None,
|
||||
'blog_id': None,
|
||||
'nav_list': dict(),
|
||||
@@ -28,7 +27,7 @@ class website_mail(http.Controller):
|
||||
'mail_group_id': mail_group_id,
|
||||
}
|
||||
domain = mail_group_id and [("res_id", "=", mail_group_id)] or []
|
||||
|
||||
|
||||
for group in message_obj.read_group(request.cr, request.uid, domain + group_obj.get_public_blog(request.cr, request.uid), ['subject', 'date'], groupby="date", orderby="create_date asc"):
|
||||
year = group['date'].split(" ")[1]
|
||||
if not values['nav_list'].get(year):
|
||||
@@ -58,13 +57,11 @@ class website_mail(http.Controller):
|
||||
|
||||
@http.route(['/blog/nav'], type='http', auth="public")
|
||||
def nav(self, **post):
|
||||
request.uid = website.get_request.uid()
|
||||
comment_ids = request.registry['mail.group'].get_public_message_ids(request.cr, request.uid, domain=safe_eval(post.get('domain')), order="create_date asc", limit=None)
|
||||
return simplejson.dumps(request.registry['mail.message'].read(request.cr, request.uid, comment_ids, ['website_published', 'subject', 'res_id']))
|
||||
|
||||
@http.route(['/blog/publish'], type='http', auth="public")
|
||||
def publish(self, **post):
|
||||
request.uid = website.get_request.uid()
|
||||
message_id = int(post['message_id'])
|
||||
message_obj = request.registry['mail.message']
|
||||
|
||||
@@ -76,7 +73,6 @@ class website_mail(http.Controller):
|
||||
|
||||
@http.route(['/blog/<int:mail_group_id>/<int:blog_id>/post'], type='http', auth="public")
|
||||
def blog_post(self, mail_group_id=None, blog_id=None, **post):
|
||||
request.uid = website.get_request.uid()
|
||||
url = request.httprequest.host_url
|
||||
if post.get('body'):
|
||||
request.session.body = post.get('body')
|
||||
@@ -101,7 +97,6 @@ class website_mail(http.Controller):
|
||||
|
||||
@http.route(['/blog/<int:mail_group_id>/new'], type='http', auth="public")
|
||||
def new_blog_post(self, mail_group_id=None, **post):
|
||||
request.uid = website.get_request.uid()
|
||||
blog_id = request.registry['mail.group'].message_post(request.cr, request.uid, mail_group_id,
|
||||
body=_("Blog content.<br/>Please edit this content then you can publish this blog."),
|
||||
subject=_("Blog title"),
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
.css_website_mail .media .label-success {
|
||||
display: none;
|
||||
}
|
||||
.css_website_mail .css_published .label-important {
|
||||
display: none;
|
||||
}
|
||||
.css_website_mail .css_published .label-success {
|
||||
display: inline-block;
|
||||
}
|
||||
.css_website_mail .has-error {
|
||||
border-color: red;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
@import "compass/css3"
|
||||
|
||||
.css_website_mail
|
||||
.media
|
||||
.label-success
|
||||
display: none
|
||||
.css_published
|
||||
.label-important
|
||||
display: none
|
||||
.label-success
|
||||
display: inline-block
|
||||
.has-error
|
||||
border-color: red
|
||||
.css_nav_month
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
$(document).ready(function () {
|
||||
$('.js_website_mail').on('click', '.js_publish', function (e) {
|
||||
$('.js_website_mail').on('click', '.js_publish, .js_unpublish', function (e) {
|
||||
e.preventDefault();
|
||||
var $media = $(this).parent();
|
||||
$media.toggleClass('css_published');
|
||||
$.post('/blog/publish/', {'message_id': $(this).data('id')}, function (result) {
|
||||
if (+result) $media.addClass('css_published');
|
||||
else $media.removeClass('css_published');
|
||||
var $link = $(this).parent();
|
||||
$link.find('.js_publish, .js_unpublish').addClass("hidden");
|
||||
var $unp = $link.find(".js_unpublish");
|
||||
var $p = $link.find(".js_publish");
|
||||
$.post('/blog/publish/', {'message_id': $link.data('id')}, function (result) {
|
||||
if (+result) {
|
||||
$p.addClass("hidden");
|
||||
$unp.removeClass("hidden");
|
||||
} else {
|
||||
$p.removeClass("hidden");
|
||||
$unp.addClass("hidden");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@
|
||||
<t t-raw="head"/>
|
||||
</t>
|
||||
<t t-set="title">Blog</t>
|
||||
<div class="container mt48 css_website_mail js_website_mail">
|
||||
<div class="container mt48 js_website_mail">
|
||||
<div class="row">
|
||||
<div class="span4">
|
||||
<ul class="nav nav-list">
|
||||
<a t-if="mail_group_id" t-att-href="'/blog/%%s/new' %% mail_group_id" class="btn" groups="group_website_mail_manager">Add a new Blog</a>
|
||||
<a t-if="mail_group_id and editable" t-att-href="'/blog/%%s/new' %% mail_group_id" class="btn">Add a new Blog</a>
|
||||
<li class="nav-header">BLOG ARCHIVE</li>
|
||||
<!-- TODO: check qweb iteration -->
|
||||
<t t-foreach="nav_list" t-as="year">
|
||||
@@ -68,10 +68,10 @@
|
||||
</div>
|
||||
<div class="span8" t-if="blog_id">
|
||||
<div class="media">
|
||||
<div t-att-class="'media-body well %%s' %% (blog_id.website_published and 'css_published' or '')">
|
||||
<a href="#" title="Click to publish or unpublish this blog" t-att-data-id="blog_id.id" class="js_publish pull-right" groups="group_website_mail_manager">
|
||||
<span class="label label-success">Unpublish</span>
|
||||
<span class="label label-important">Publish</span>
|
||||
<div t-att-class="media-body well">
|
||||
<a href="#" t-att-data-id="blog_id.id" class="pull-right" t-if="editable">
|
||||
<span t-att-class="'label label-success js_unpublish %%s' %% (not blog_id.website_published and 'hidden' or '')">Click to Unpublish</span>
|
||||
<span t-att-class="'label label-important js_publish %%s' %% (blog_id.website_published and 'hidden' or '')">Click to Publish</span>
|
||||
</a>
|
||||
<h3 t-record="blog_id" t-field="subject"></h3>
|
||||
<div t-record="blog_id" t-field="body"></div>
|
||||
@@ -84,10 +84,10 @@
|
||||
<t t-foreach="comments">
|
||||
<!-- TODO: check qweb iteration -->
|
||||
<li class="media">
|
||||
<div t-att-class="'media-body %%s' %% (website_published and 'css_published' or '')">
|
||||
<a href="#" title="Click to publish or unpublish this message" t-att-data-id="id" class="js_publish pull-right" groups="group_website_mail_manager">
|
||||
<span class="label label-success">Unpublish</span>
|
||||
<span class="label label-important">Publish</span>
|
||||
<div class="media-body">
|
||||
<a href="#" t-att-data-id="blog_id.id" class="pull-right" t-if="editable">
|
||||
<span t-att-class="'label label-success js_unpublish %%s' %% (not website_published and 'hidden' or '')">Click to Unpublish</span>
|
||||
<span t-att-class="'label label-important js_publish %%s' %% (website_published and 'hidden' or '')">Click to Publish</span>
|
||||
</a>
|
||||
<t t-raw="body"/>
|
||||
<small class="pull-right muted text-right">
|
||||
@@ -109,9 +109,9 @@
|
||||
<t t-foreach="blog_ids" t-as="blog">
|
||||
<li class="media well">
|
||||
<div t-att-class="'media-body %%s' %% (blog.website_published and 'css_published' or '')">
|
||||
<a href="#" title="Click to publish or unpublish this message" t-att-data-id="blog.id" class="js_publish pull-right" groups="group_website_mail_manager">
|
||||
<span class="label label-success">Unpublish</span>
|
||||
<span class="label label-important">Publish</span>
|
||||
<a href="#" t-att-data-id="blog.id" class="pull-right" t-if="editable">
|
||||
<span t-att-class="'label label-success js_unpublish %%s' %% (not blog.website_published and 'hidden' or '')">Click to Unpublish</span>
|
||||
<span t-att-class="'label label-important js_publish %%s' %% (blog.website_published and 'hidden' or '')">Click to Publish</span>
|
||||
</a>
|
||||
<h4 class="media-heading" ><a t-att-href="'/blog/%%s/%%s' %% (blog.res_id, blog.id)" t-record="blog" t-field="subject"></a></h4>
|
||||
<div class="media">
|
||||
|
||||
@@ -14,8 +14,8 @@ class Ecommerce(http.Controller):
|
||||
return category_obj.browse(request.cr, request.uid, category_ids)
|
||||
|
||||
def get_current_order(self):
|
||||
order = self.get_order(request.httprequest.session.get('ecommerce_order'))
|
||||
request.httprequest.session['ecommerce_order'] = order.id
|
||||
order = self.get_order(request.httprequest.session.get('ecommerce_order_id'))
|
||||
request.httprequest.session['ecommerce_order_id'] = order.id
|
||||
return order
|
||||
|
||||
def get_order(self, order_id=None):
|
||||
@@ -30,7 +30,9 @@ class Ecommerce(http.Controller):
|
||||
if not order_id:
|
||||
fields = [k for k, v in order_obj._columns.items()]
|
||||
order_value = order_obj.default_get(request.cr, request.uid, fields)
|
||||
order_value['partner_id'] = partner_id or request.registry.get('res.users').browse(request.cr, request.uid, request.uid).partner_id.id
|
||||
order_value['partner_id'] = request.uid != request.public_uid and \
|
||||
request.registry.get('res.users').browse(request.cr, request.uid, request.uid).partner_id.id or \
|
||||
None
|
||||
order_value.update(order_obj.onchange_partner_id(request.cr, request.uid, [], request.uid, context={})['value'])
|
||||
order_id = order_obj.create(request.cr, request.uid, order_value)
|
||||
return order_obj.browse(request.cr, request.uid, order_id)
|
||||
@@ -65,7 +67,7 @@ class Ecommerce(http.Controller):
|
||||
product_ids.append(p[0])
|
||||
return request.registry.get('product.product').browse(request.cr, request.uid, product_ids)
|
||||
|
||||
@http.route(['/shop', '/shop/category/<cat_id>'], type='http', auth="admin")
|
||||
@http.route(['/shop', '/shop/category/<cat_id>'], type='http', auth="public")
|
||||
def category(self, cat_id=0, offset=0, **post):
|
||||
|
||||
domain = []
|
||||
@@ -86,7 +88,7 @@ class Ecommerce(http.Controller):
|
||||
html = self.render("website_sale.products", values)
|
||||
return html
|
||||
|
||||
@http.route(['/shop/product/<product_id>'], type='http', auth="admin")
|
||||
@http.route(['/shop/product/<product_id>'], type='http', auth="public")
|
||||
def product(self, cat_id=0, product_id=0):
|
||||
order = self.get_current_order()
|
||||
|
||||
@@ -104,7 +106,7 @@ class Ecommerce(http.Controller):
|
||||
html = self.render("website_sale.product", values)
|
||||
return html
|
||||
|
||||
@http.route(['/shop/mycart'], type='http', auth="admin")
|
||||
@http.route(['/shop/mycart'], type='http', auth="public")
|
||||
def mycart(self, **post):
|
||||
order = self.get_current_order()
|
||||
|
||||
@@ -120,7 +122,7 @@ class Ecommerce(http.Controller):
|
||||
html = self.render("website_sale.mycart", values)
|
||||
return html
|
||||
|
||||
@http.route(['/shop/add_cart'], type='http', auth="admin")
|
||||
@http.route(['/shop/add_cart'], type='http', auth="public")
|
||||
def add_cart(self, product_id=0, remove=False):
|
||||
|
||||
context = {}
|
||||
@@ -162,15 +164,15 @@ class Ecommerce(http.Controller):
|
||||
order_line_id = order_line_obj.create(request.cr, request.uid, values, context=context)
|
||||
order.write({'order_line': [(4, order_line_id)]}, context=context)
|
||||
|
||||
html = self.render("website_sale.total", self.get_values())
|
||||
html = self.render("website_sale.total")
|
||||
|
||||
return simplejson.dumps({"quantity": quantity, "totalHTML": html})
|
||||
|
||||
@http.route(['/shop/remove_cart'], type='http', auth="admin")
|
||||
@http.route(['/shop/remove_cart'], type='http', auth="public")
|
||||
def remove_cart(self, product_id=0):
|
||||
return self.add_cart(product_id=product_id, remove=True)
|
||||
|
||||
@http.route(['/shop/checkout'], type='http', auth="admin")
|
||||
@http.route(['/shop/checkout'], type='http', auth="public")
|
||||
def checkout(self, **post):
|
||||
order = self.get_current_order()
|
||||
|
||||
@@ -188,8 +190,8 @@ class Ecommerce(http.Controller):
|
||||
values = {'partner': False}
|
||||
|
||||
if request.uid != request.public_uid:
|
||||
values['partner'] = partner_obj.browse(request.cr, request.uid, partner_id)
|
||||
shipping_ids = partner_obj.search(request.cr, request.uid, [("parent_id", "=", partner_id), ('type', "=", 'delivery')])
|
||||
values['partner'] = user_obj.browse(request.cr, request.uid, request.uid).partner_id
|
||||
shipping_ids = partner_obj.search(request.cr, request.uid, [("parent_id", "=", values['partner'].id), ('type', "=", 'delivery')])
|
||||
values['shipping'] = None
|
||||
if shipping_ids:
|
||||
values['shipping'] = partner_obj.browse(request.cr, request.uid, shipping_ids[0])
|
||||
@@ -205,7 +207,7 @@ class Ecommerce(http.Controller):
|
||||
|
||||
return self.render("website_sale.checkout", values)
|
||||
|
||||
@http.route(['/shop/confirm_order'], type='http', auth="admin")
|
||||
@http.route(['/shop/confirm_order'], type='http', auth="public")
|
||||
def confirm_order(self, **post):
|
||||
order = self.get_current_order()
|
||||
|
||||
@@ -291,16 +293,16 @@ class Ecommerce(http.Controller):
|
||||
json['validation'] = True
|
||||
return simplejson.dumps(json)
|
||||
|
||||
@http.route(['/shop/confirmed'], type='http', auth="admin")
|
||||
@http.route(['/shop/confirmed'], type='http', auth="public")
|
||||
def confirmed(self, **post):
|
||||
|
||||
if request.httprequest.session.get('ecommerce_order'):
|
||||
if request.httprequest.session.get('ecommerce_order_id'):
|
||||
order = self.get_current_order()
|
||||
if order.state != 'draft':
|
||||
request.httprequest.session['ecommerce_order_old'] = order.id
|
||||
request.httprequest.session['ecommerce_order'] = None
|
||||
request.httprequest.session['ecommerce_order_id_old'] = order.id
|
||||
request.httprequest.session['ecommerce_order_id'] = None
|
||||
|
||||
order_old = self.get_order(request.httprequest.session.get('ecommerce_order_old'))
|
||||
order_old = self.get_order(request.httprequest.session.get('ecommerce_order_id_old'))
|
||||
if not order_old.order_line:
|
||||
return self.mycart(**post)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user