[FIX] website_sale: filters and partner controller
bzr revid: chm@openerp.com-20131205162240-33wfteow79zlbdrn
This commit is contained in:
@@ -0,0 +1 @@
|
||||
import main
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import openerp
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.addons.website.models import website
|
||||
import werkzeug
|
||||
|
||||
white_list = ["grade_id", "name", "parent_id", 'website_short_description', "website_published",
|
||||
"website_description", "tel", "fax", "image", "image_small", "image_medium"]
|
||||
|
||||
def get_partner_template_value(partner, add_white_list=None):
|
||||
ctx = dict(request.context, show_address=True)
|
||||
partner_obj = request.registry['res.partner']
|
||||
partner_id = partner.id
|
||||
partner_ids = partner_obj.search(request.cr, request.uid, [('id', '=', partner_id)], context=request.context)
|
||||
if not partner.exists() or not partner_ids:
|
||||
partner = None
|
||||
|
||||
partner_data = partner_obj.read(
|
||||
request.cr, openerp.SUPERUSER_ID, [partner_id], white_list + (add_white_list or []), context=ctx)[0]
|
||||
|
||||
if not partner_data["website_published"]:
|
||||
return None
|
||||
|
||||
partner_data['name_get'] = partner_obj.name_get(request.cr, openerp.SUPERUSER_ID, [partner_id],context=request.context)[0]
|
||||
|
||||
partner_data['address'] = '<br/>'.join(partner_obj.name_get(
|
||||
request.cr, openerp.SUPERUSER_ID, [partner_id],context=ctx)[0][1].split('\n')[1:])
|
||||
|
||||
values = {
|
||||
'partner': partner,
|
||||
'partner_data': partner_data,
|
||||
}
|
||||
return values
|
||||
|
||||
class WebsitePartner(http.Controller):
|
||||
@website.route(['/partners/<model("res.partner"):partner>/'], type='http', auth="public", multilang=True)
|
||||
def partner(self, partner, **post):
|
||||
""" Route for displaying a single partner / customer. """
|
||||
values = get_partner_template_value(partner)
|
||||
if not values:
|
||||
raise werkzeug.exceptions.NotFound
|
||||
return request.website.render("website_partner.partner_detail", values)
|
||||
@@ -121,19 +121,19 @@ class Ecommerce(http.Controller):
|
||||
return product_obj.browse(request.cr, request.uid, product_ids, context=request.context)
|
||||
|
||||
def has_search_filter(self, attribute_id, value_id=None):
|
||||
if request.httprequest.args.get('filter'):
|
||||
filter = simplejson.loads(request.httprequest.args['filter'])
|
||||
if request.httprequest.args.get('filters'):
|
||||
filters = simplejson.loads(request.httprequest.args['filters'])
|
||||
else:
|
||||
filter = []
|
||||
for key_val in filter:
|
||||
filters = []
|
||||
for key_val in filters:
|
||||
if key_val[0] == attribute_id and (not value_id or value_id in key_val[1:]):
|
||||
return key_val
|
||||
return False
|
||||
|
||||
@website.route(['/shop/filter/'], type='http', auth="public", multilang=True)
|
||||
def filter(self, **post):
|
||||
@website.route(['/shop/filters/'], type='http', auth="public", multilang=True)
|
||||
def filters(self, **post):
|
||||
index = []
|
||||
filter = []
|
||||
filters = []
|
||||
for key, val in post.items():
|
||||
cat = key.split("-")
|
||||
if len(cat) < 3 or cat[2] in ('max','minmem','maxmem'):
|
||||
@@ -145,19 +145,19 @@ class Ecommerce(http.Controller):
|
||||
_max = int(post.pop("att-%s-max" % cat[1]))
|
||||
_min = int(val)
|
||||
if (minmem != _min or maxmem != _max) and cat_id not in index:
|
||||
filter.append([cat_id , [_min, _max] ])
|
||||
filters.append([cat_id , [_min, _max] ])
|
||||
index.append(cat_id)
|
||||
elif cat_id not in index:
|
||||
filter.append([ cat_id, int(cat[2]) ])
|
||||
filters.append([ cat_id, int(cat[2]) ])
|
||||
index.append(cat_id)
|
||||
else:
|
||||
cat[2] = int(cat[2])
|
||||
if cat[2] not in filter[index.index(cat_id)][1:]:
|
||||
filter[index.index(cat_id)].append( cat[2] )
|
||||
if cat[2] not in filters[index.index(cat_id)][1:]:
|
||||
filters[index.index(cat_id)].append( cat[2] )
|
||||
post.pop(key)
|
||||
|
||||
return request.redirect("/shop/?filter=%s%s%s" % (
|
||||
simplejson.dumps(filter),
|
||||
return request.redirect("/shop/?filters=%s%s%s" % (
|
||||
simplejson.dumps(filters),
|
||||
post.get("search") and ("&search=%s" % post.get("search")) or "",
|
||||
post.get("category") and ("&category=%s" % post.get("category")) or ""
|
||||
))
|
||||
@@ -188,7 +188,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_domain='', search='', **post):
|
||||
def shop(self, category=0, page=0, filters='', 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()
|
||||
@@ -198,10 +198,10 @@ class Ecommerce(http.Controller):
|
||||
('description', 'ilike', "%%%s%%" % search)]
|
||||
if category:
|
||||
domain.append(('product_variant_ids.public_categ_id', 'child_of', category))
|
||||
if filter_domain:
|
||||
filter_domain = simplejson.loads(filter_domain)
|
||||
if filter_domain:
|
||||
ids = self.attributes_to_ids(filter_domain)
|
||||
if filters:
|
||||
filters = simplejson.loads(filters)
|
||||
if filters:
|
||||
ids = self.attributes_to_ids(filters)
|
||||
domain.append(('id', 'in', ids or [0]))
|
||||
|
||||
product_count = product_obj.search_count(cr, uid, domain, context=context)
|
||||
@@ -228,10 +228,12 @@ class Ecommerce(http.Controller):
|
||||
values = {
|
||||
'products': products,
|
||||
'bins': table_compute().process(products),
|
||||
'rows': PPR,
|
||||
'range': range,
|
||||
'search': {
|
||||
'search': search,
|
||||
'category': category,
|
||||
'filter_domain': filter_domain,
|
||||
'filters': filters,
|
||||
},
|
||||
'pager': pager,
|
||||
'styles': styles,
|
||||
@@ -242,7 +244,7 @@ class Ecommerce(http.Controller):
|
||||
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_domain='', **kwargs):
|
||||
def product(self, product, search='', category='', filters='', **kwargs):
|
||||
website.preload_records(product, on_error="website_sale.404")
|
||||
|
||||
category_obj = request.registry.get('product.public.category')
|
||||
@@ -265,7 +267,7 @@ class Ecommerce(http.Controller):
|
||||
'search': {
|
||||
'search': search,
|
||||
'category': category and str(category.id),
|
||||
'filter': filter_domain,
|
||||
'filters': filters,
|
||||
}
|
||||
}
|
||||
return request.website.render("website_sale.product", values)
|
||||
|
||||
@@ -40,7 +40,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_domain" t-att-value="search.get('filter_domain') or ''"/>
|
||||
<input type="hidden" name="filters" t-att-value="search.get('filters') or ''"/>
|
||||
<input type="text" name="search" class="search-query form-control" placeholder="Search..." t-att-value="search.get('search') or ''"/>
|
||||
</template>
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
<div class="ribbon">Promo</div>
|
||||
</div>
|
||||
<div class="oe_product_description">
|
||||
<a t-href="/shop/product/#{ slug(product) }/" t-keep-query="category,search,filter_domain">
|
||||
<a t-href="/shop/product/#{ slug(product) }/" t-keep-query="category,search,filters">
|
||||
<b t-field="product.name"/>
|
||||
</a>
|
||||
</div>
|
||||
@@ -69,7 +69,7 @@
|
||||
</b>
|
||||
</div>
|
||||
<div class="oe_product_image text-center">
|
||||
<a t-href="/shop/product/#{ product.id }/" t-keep-query="category,search,filter_domain">
|
||||
<a t-href="/shop/product/#{ product.id }/" t-keep-query="category,search,filters">
|
||||
<span t-field="product.image" t-field-options='{"widget": "image"}'/>
|
||||
</a>
|
||||
</div>
|
||||
@@ -105,12 +105,14 @@
|
||||
<div class="col-md-12" id="products_grid">
|
||||
<table width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td t-foreach="range(0,rows)" t-as="row" t-attf-width="#{100/rows}%"></td>
|
||||
</tr>
|
||||
<tr t-foreach="bins" t-as="tr_product">
|
||||
<t t-foreach="tr_product" t-as="td_product">
|
||||
<t t-if="td_product">
|
||||
<t t-set="product" t-value="td_product['product']"/>
|
||||
<td t-att-colspan="td_product['x']"
|
||||
t-attf-width="#{td_product['x']*25}%"
|
||||
t-att-rowspan="td_product['y']"
|
||||
t-attf-class="oe_product oe-height-#{td_product['y']*2} #{ td_product['class'] }">
|
||||
|
||||
@@ -254,7 +256,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_domain"><span t-field="category.name"/></a></li>
|
||||
<li t-if="search.get('category')"><a t-href="/shop/" t-keep-query="category,search,filters"><span t-field="category.name"/></a></li>
|
||||
<li class="active"><span t-field="product.name"/></li>
|
||||
</ol>
|
||||
</div><div class="col-sm-3">
|
||||
@@ -525,7 +527,7 @@
|
||||
|
||||
<template id="products_attributes" inherit_option_id="website_sale.products" name="Product Filters and Attributes">
|
||||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||
<form t-action="/shop/filter/" method="post" t-keep-query="category,search">
|
||||
<form t-action="/shop/filters/" method="post" t-keep-query="category,search">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<t t-set="attribute_ids" t-value="Ecommerce.get_attribute_ids()"/>
|
||||
<t t-foreach="attribute_ids" t-as="attribute_id">
|
||||
@@ -558,7 +560,7 @@
|
||||
</t>
|
||||
</ul>
|
||||
<button class="btn btn-xs btn-primary mt16">Apply filter</button>
|
||||
<a t-href="/shop/" t-keep-query="category,search,add_filter" class="btn btn-xs btn-default mt16">Cancel filter</a>
|
||||
<a t-href="/shop/" t-keep-query="category,search" class="btn btn-xs btn-default mt16">Cancel filter</a>
|
||||
</form>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='products_grid_before']" position="attributes">
|
||||
|
||||
Reference in New Issue
Block a user