[IMP] Speed improvements
bzr revid: fp@tinyerp.com-20131201172541-p8403347rv08uurh
This commit is contained in:
parent
dd62046680
commit
d6f77f5853
|
@ -59,6 +59,22 @@ class Website(openerp.addons.web.controllers.main.Home):
|
|||
return werkzeug.wrappers.Response(url, mimetype='text/plain')
|
||||
return werkzeug.utils.redirect(url)
|
||||
|
||||
@website.route('/website/test', type='http', auth="admin")
|
||||
def website_test(self, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
pobj = request.registry['product.template']
|
||||
pids = pobj.search(cr, uid, [('website_published','=',True)], context=context)
|
||||
print 'Start', len(pids), '-'*50
|
||||
products = pobj.browse(cr, uid, pids, context=context)
|
||||
for p in products:
|
||||
for var in p.product_variant_ids:
|
||||
print '1', var.lst_price
|
||||
print '2', var.price
|
||||
print p.name
|
||||
print 'End', '-'*50
|
||||
return 'Hello World!'
|
||||
|
||||
|
||||
@website.route('/website/theme_change', type='http', auth="admin")
|
||||
def theme_change(self, theme_id=False, **kwargs):
|
||||
imd = request.registry['ir.model.data']
|
||||
|
|
|
@ -102,25 +102,6 @@ class Ecommerce(http.Controller):
|
|||
attributes_ids = attributes_obj.search(request.cr, request.uid, [], context=request.context)
|
||||
return attributes_obj.browse(request.cr, request.uid, attributes_ids, context=request.context)
|
||||
|
||||
def get_categories(self):
|
||||
domain = [('parent_id', '=', False)]
|
||||
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
category_ids = category_obj.search(request.cr, SUPERUSER_ID, domain, context=request.context)
|
||||
categories = category_obj.browse(request.cr, SUPERUSER_ID, category_ids, context=request.context)
|
||||
|
||||
product_obj = request.registry.get('product.product')
|
||||
groups = product_obj.read_group(request.cr, SUPERUSER_ID, [("sale_ok", "=", True), ('website_published', '=', True)], ['public_categ_id'], 'public_categ_id', context=request.context)
|
||||
full_category_ids = [group['public_categ_id'][0] for group in groups if group['public_categ_id']]
|
||||
|
||||
for cat_id in category_obj.browse(request.cr, SUPERUSER_ID, full_category_ids, context=request.context):
|
||||
while cat_id.parent_id:
|
||||
cat_id = cat_id.parent_id
|
||||
full_category_ids.append(cat_id.id)
|
||||
full_category_ids.append(1)
|
||||
|
||||
return (categories, full_category_ids)
|
||||
|
||||
def get_pricelist(self):
|
||||
return request.registry.get('website').get_pricelist_id(request.cr, request.uid, None, context=request.context)
|
||||
|
||||
|
@ -199,7 +180,7 @@ class Ecommerce(http.Controller):
|
|||
'/shop/category/<int:category>/',
|
||||
'/shop/category/<int:category>/page/<int:page>/'
|
||||
], type='http', auth="public", multilang=True)
|
||||
def shop(self, category=0, page=0, filter='', search='', **post):
|
||||
def shop(self, category=0, page=0, filter_domain='', search='', **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
product_obj = request.registry.get('product.template')
|
||||
domain = request.registry.get('website').get_website_sale_domain()
|
||||
|
@ -209,10 +190,10 @@ class Ecommerce(http.Controller):
|
|||
('description', 'ilike', "%%%s%%" % search)]
|
||||
if category:
|
||||
domain.append(('product_variant_ids.public_categ_id', 'child_of', category))
|
||||
if filter:
|
||||
filter = simplejson.loads(filter)
|
||||
if filter:
|
||||
ids = self.attributes_to_ids(filter)
|
||||
if filter_domain:
|
||||
filter_domain = simplejson.loads(filter_domain)
|
||||
if filter_domain:
|
||||
ids = self.attributes_to_ids(filter_domain)
|
||||
domain.append(('id', 'in', ids or [0]))
|
||||
|
||||
product_count = product_obj.search_count(cr, uid, domain, context=context)
|
||||
|
@ -231,24 +212,29 @@ class Ecommerce(http.Controller):
|
|||
except:
|
||||
pass
|
||||
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
category_ids = category_obj.search(cr, uid, [], context=context)
|
||||
categories = category_obj.browse(cr, uid, category_ids, context=context)
|
||||
categs = filter(lambda x: not x.parent_id, categories)
|
||||
|
||||
values = {
|
||||
'products': products,
|
||||
'bins': table_compute().process(products),
|
||||
'search': {
|
||||
'search': search,
|
||||
'category': category,
|
||||
'filter': filter,
|
||||
'filter_domain': filter_domain,
|
||||
},
|
||||
'pager': pager,
|
||||
'styles': styles,
|
||||
# 'Ecommerce': self,
|
||||
# 'product_ids_for_holes': fill_hole,
|
||||
# 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
|
||||
'categories': categs,
|
||||
'Ecommerce': self, # TODO fp: Should be removed
|
||||
'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
|
||||
}
|
||||
return request.website.render("website_sale.products", values)
|
||||
|
||||
@website.route(['/shop/product/<model("product.template"):product>/'], type='http', auth="public", multilang=True)
|
||||
def product(self, product, search='', category='', filter='', **kwargs):
|
||||
def product(self, product, search='', category='', filter_domain='', **kwargs):
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
|
||||
category_ids = category_obj.search(request.cr, request.uid, [], context=request.context)
|
||||
|
@ -269,7 +255,7 @@ class Ecommerce(http.Controller):
|
|||
'search': {
|
||||
'search': search,
|
||||
'category': category and str(category.id),
|
||||
'filter': filter,
|
||||
'filter': filter_domain,
|
||||
}
|
||||
}
|
||||
return request.website.render("website_sale.product", values)
|
||||
|
@ -369,7 +355,6 @@ class Ecommerce(http.Controller):
|
|||
|
||||
values = {
|
||||
'int': int,
|
||||
'get_categories': self.get_categories,
|
||||
'suggested_products': prod_obj.browse(cr, uid, suggested_products, context),
|
||||
}
|
||||
return request.website.render("website_sale.mycart", values)
|
||||
|
|
|
@ -24,12 +24,10 @@
|
|||
|
||||
<template id="categories_recursive" name="Category list">
|
||||
<li t-att-class="str(category.id) == search.get('category') and 'active' or ''">
|
||||
<a t-att-class="category.id not in categ[1] and 'unpublish' or ''" t-href="/shop/category/#{ category.id }/" t-field="category.name"></a>
|
||||
<a t-href="/shop/category/#{ category.id }/" t-field="category.name"></a>
|
||||
<ul t-if="category.child_id" class="nav nav-pills nav-stacked nav-hierarchy">
|
||||
<t t-foreach="category.child_id" t-as="category">
|
||||
<t t-if="category.id in categ[1] or editable">
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -39,7 +37,7 @@
|
|||
|
||||
<template id="search" name="Search hidden fields">
|
||||
<input type="hidden" name="category" t-att-value="search.get('category') or ''"/>
|
||||
<input type="hidden" name="filter" t-att-value="search.get('filter') or ''"/>
|
||||
<input type="hidden" name="filter_domain" t-att-value="search.get('filter_domain') or ''"/>
|
||||
<input type="text" name="search" class="search-query form-control" placeholder="Search..." t-att-value="search.get('search') or ''"/>
|
||||
</template>
|
||||
|
||||
|
@ -48,7 +46,7 @@
|
|||
<div class="ribbon"><span contentEditable="true">Promo</span></div>
|
||||
</div>
|
||||
<div class="oe_product_description">
|
||||
<a t-href="/shop/product/#{ product.id }/" t-keep-query="category,search,filter">
|
||||
<a t-href="/shop/product/#{ product.id }/" t-keep-query="category,search,filter_domain">
|
||||
<b t-field="product.name"/>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -68,7 +66,7 @@
|
|||
</b>
|
||||
</div>
|
||||
<div class="oe_product_image text-center">
|
||||
<a t-href="/shop/product/#{ product.id }/" t-keep-query="category,search,filter">
|
||||
<a t-href="/shop/product/#{ product.id }/" t-keep-query="category,search,filter_domain">
|
||||
<span t-field="product.image" t-field-options='{"widget": "image"}'/>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -241,7 +239,7 @@
|
|||
<div class="col-sm-5">
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/shop">Products</a></li>
|
||||
<li t-if="search.get('category')"><a t-href="/shop/" t-keep-query="category,search,filter"><span t-field="category.name"/></a></li>
|
||||
<li t-if="search.get('category')"><a t-href="/shop/" t-keep-query="category,search,filter_domain"><span t-field="category.name"/></a></li>
|
||||
<li class="active"><span t-field="product.name"/></li>
|
||||
</ol>
|
||||
</div><div class="col-sm-3">
|
||||
|
@ -496,8 +494,7 @@
|
|||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<li t-att-class=" '' if search.get('category') else 'active' "><a href="/shop/">All Products</a></li>
|
||||
<t t-set="categ" t-value="Ecommerce.get_categories()"/>
|
||||
<t t-foreach="categ[0]" t-as="category">
|
||||
<t t-foreach="categories" t-as="category">
|
||||
<t t-call="website_sale.categories_recursive"/>
|
||||
</t>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue