[IMP] website: refact. python for website publish button
bzr revid: chm@openerp.com-20130814084505-5ynbrmfvbu48v7kx
This commit is contained in:
@@ -2,14 +2,12 @@
|
|||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
from openerp.addons.web import http
|
from openerp.addons.web import http
|
||||||
from openerp.addons.web.controllers.main import manifest_list
|
|
||||||
from openerp.addons.web.http import request
|
from openerp.addons.web.http import request
|
||||||
import werkzeug
|
import werkzeug
|
||||||
import werkzeug.exceptions
|
import werkzeug.exceptions
|
||||||
@@ -17,6 +15,16 @@ import werkzeug.wrappers
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def auth_method_public():
|
||||||
|
registry = openerp.modules.registry.RegistryManager.get(request.db)
|
||||||
|
if not request.session.uid:
|
||||||
|
request.uid = registry['website'].get_public_user().id
|
||||||
|
else:
|
||||||
|
request.uid = request.session.uid
|
||||||
|
http.auth_methods['public'] = auth_method_public
|
||||||
|
|
||||||
|
|
||||||
class Website(openerp.addons.web.controllers.main.Home):
|
class Website(openerp.addons.web.controllers.main.Home):
|
||||||
@http.route('/', type='http', auth="admin")
|
@http.route('/', type='http', auth="admin")
|
||||||
def index(self, **kw):
|
def index(self, **kw):
|
||||||
@@ -146,4 +154,15 @@ class Website(openerp.addons.web.controllers.main.Home):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@http.route(['/website/publish/'], type='http', auth="public")
|
||||||
|
def publish(self, **post):
|
||||||
|
_id = int(post['id'])
|
||||||
|
_object = request.registry[post['object']]
|
||||||
|
|
||||||
|
obj = _object.browse(request.cr, request.uid, _id)
|
||||||
|
_object.write(request.cr, request.uid, [_id], {'website_published': not obj.website_published})
|
||||||
|
obj = _object.browse(request.cr, request.uid, _id)
|
||||||
|
|
||||||
|
return obj.website_published and "1" or "0"
|
||||||
|
|
||||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|||||||
@@ -389,15 +389,7 @@ $(function () {
|
|||||||
$link.find('.js_publish, .js_unpublish').addClass("hidden");
|
$link.find('.js_publish, .js_unpublish').addClass("hidden");
|
||||||
var $unp = $link.find(".js_unpublish");
|
var $unp = $link.find(".js_unpublish");
|
||||||
var $p = $link.find(".js_publish");
|
var $p = $link.find(".js_publish");
|
||||||
|
$.post('/website/publish', {'id': $link.data('id'), 'object': $link.data('object')}, function (result) {
|
||||||
var paths = document.location.pathname.split('/');
|
|
||||||
var url = '/' + paths[1];
|
|
||||||
if (paths[1] === 'page') {
|
|
||||||
url += '/' + paths[2];
|
|
||||||
}
|
|
||||||
url += '/publish';
|
|
||||||
|
|
||||||
$.post(url, {'id': $link.data('id')}, function (result) {
|
|
||||||
if (+result) {
|
if (+result) {
|
||||||
$p.addClass("hidden");
|
$p.addClass("hidden");
|
||||||
$unp.removeClass("hidden");
|
$unp.removeClass("hidden");
|
||||||
|
|||||||
@@ -455,7 +455,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="publish">
|
<template id="publish">
|
||||||
<a href="#" t-att-data-id="object.id" class="pull-right" t-if="editable">
|
<a href="#" t-att-data-id="object.id" t-att-data-object="object._name" class="pull-right" t-if="editable" t-ignore="true">
|
||||||
<span t-att-class="'label label-success js_unpublish %%s' %% (not object.website_published and 'hidden' or '')">Unpublish</span>
|
<span t-att-class="'label label-success js_unpublish %%s' %% (not object.website_published and 'hidden' or '')">Unpublish</span>
|
||||||
<span t-att-class="'label label-important js_publish %%s' %% (object.website_published and 'hidden' or '')">Publish</span>
|
<span t-att-class="'label label-important js_publish %%s' %% (object.website_published and 'hidden' or '')">Publish</span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -149,15 +149,3 @@ class website_event(http.Controller):
|
|||||||
if not _values:
|
if not _values:
|
||||||
return werkzeug.utils.redirect("/event/%s/" % event_id)
|
return werkzeug.utils.redirect("/event/%s/" % event_id)
|
||||||
return werkzeug.utils.redirect("/shop/checkout")
|
return werkzeug.utils.redirect("/shop/checkout")
|
||||||
|
|
||||||
@http.route(['/event/publish'], type='http', auth="public")
|
|
||||||
def publish(self, **post):
|
|
||||||
obj_id = int(post['id'])
|
|
||||||
data_obj = request.registry['event.event']
|
|
||||||
|
|
||||||
obj = data_obj.browse(request.cr, request.uid, obj_id)
|
|
||||||
data_obj.write(request.cr, request.uid, [obj_id], {'website_published': not obj.website_published})
|
|
||||||
obj = data_obj.browse(request.cr, request.uid, obj_id)
|
|
||||||
|
|
||||||
return obj.website_published and "1" or "0"
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,3 @@ class website_hr(http.Controller):
|
|||||||
'employee_ids': hr_obj.browse(request.cr, request.uid, employee_ids)
|
'employee_ids': hr_obj.browse(request.cr, request.uid, employee_ids)
|
||||||
})
|
})
|
||||||
return website.render("website.aboutus", values)
|
return website.render("website.aboutus", values)
|
||||||
|
|
||||||
@http.route(['/page/website.aboutus/publish'], type='http', auth="public")
|
|
||||||
def publish(self, **post):
|
|
||||||
obj_id = int(post['id'])
|
|
||||||
data_obj = request.registry['hr.employee']
|
|
||||||
|
|
||||||
obj = data_obj.browse(request.cr, request.uid, obj_id)
|
|
||||||
data_obj.write(request.cr, request.uid, [obj_id], {'website_published': not obj.website_published})
|
|
||||||
obj = data_obj.browse(request.cr, request.uid, obj_id)
|
|
||||||
|
|
||||||
return obj.website_published and "1" or "0"
|
|
||||||
@@ -67,17 +67,6 @@ class website_mail(http.Controller):
|
|||||||
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)
|
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']))
|
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):
|
|
||||||
message_id = int(post['id'])
|
|
||||||
message_obj = request.registry['mail.message']
|
|
||||||
|
|
||||||
blog = message_obj.browse(request.cr, request.uid, message_id)
|
|
||||||
message_obj.write(request.cr, request.uid, [message_id], {'website_published': not blog.website_published})
|
|
||||||
blog = message_obj.browse(request.cr, request.uid, message_id)
|
|
||||||
|
|
||||||
return blog.website_published and "1" or "0"
|
|
||||||
|
|
||||||
@http.route(['/blog/<int:mail_group_id>/<int:blog_id>/post'], type='http', auth="public")
|
@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):
|
def blog_post(self, mail_group_id=None, blog_id=None, **post):
|
||||||
website = request.registry['website']
|
website = request.registry['website']
|
||||||
|
|||||||
@@ -327,15 +327,4 @@ class Ecommerce(http.Controller):
|
|||||||
|
|
||||||
return website.render("website_sale.payment", values)
|
return website.render("website_sale.payment", values)
|
||||||
|
|
||||||
@http.route(['/shop/publish/'], type='http', auth="public")
|
|
||||||
def publish(self, **post):
|
|
||||||
product_id = int(post['id'])
|
|
||||||
product_obj = request.registry['product.product']
|
|
||||||
|
|
||||||
product = product_obj.browse(request.cr, request.uid, product_id)
|
|
||||||
product_obj.write(request.cr, request.uid, [product_id], {'website_published': not product.website_published})
|
|
||||||
product = product_obj.browse(request.cr, request.uid, product_id)
|
|
||||||
|
|
||||||
return product.website_published and "1" or "0"
|
|
||||||
|
|
||||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|||||||
Reference in New Issue
Block a user