[IMP] website: add '/website/image' controllers. Use img and google_map method in website_sale, website_event and website_hr
bzr revid: chm@openerp.com-20130814135741-t3bgdtzw2brq8edz
This commit is contained in:
parent
f78d8e22e0
commit
30f643c641
|
@ -12,6 +12,8 @@ from openerp.addons.web.http import request
|
|||
import werkzeug
|
||||
import werkzeug.exceptions
|
||||
import werkzeug.wrappers
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -154,6 +156,50 @@ class Website(openerp.addons.web.controllers.main.Home):
|
|||
|
||||
return response
|
||||
|
||||
@http.route('/website/image', type='http', auth="public")
|
||||
def image(self, model, id, field, **kw):
|
||||
last_update = '__last_update'
|
||||
Model = request.registry[model]
|
||||
headers = [('Content-Type', 'image/png')]
|
||||
etag = request.httprequest.headers.get('If-None-Match')
|
||||
hashed_session = hashlib.md5(request.session_id).hexdigest()
|
||||
retag = hashed_session
|
||||
|
||||
print Model.search(request.cr, request.uid, [(1,'=',1)])
|
||||
|
||||
try:
|
||||
if etag:
|
||||
date = Model.read(request.cr, request.uid, [id], [last_update], request.context)[0].get(last_update)
|
||||
if hashlib.md5(date).hexdigest() == etag:
|
||||
return werkzeug.wrappers.Response(status=304)
|
||||
|
||||
res = Model.read(request.cr, request.uid, [id], [last_update, field], request.context)[0]
|
||||
retag = hashlib.md5(res.get(last_update)).hexdigest()
|
||||
image_base64 = res.get(field)
|
||||
|
||||
if kw.get('resize'):
|
||||
resize = kw.get('resize').split(',')
|
||||
if len(resize) == 2 and int(resize[0]) and int(resize[1]):
|
||||
width = int(resize[0])
|
||||
height = int(resize[1])
|
||||
# resize maximum 500*500
|
||||
if width > 500: width = 500
|
||||
if height > 500: height = 500
|
||||
image_base64 = openerp.tools.image_resize_image(base64_source=image_base64, size=(width, height), encoding='base64', filetype='PNG')
|
||||
|
||||
image_data = base64.b64decode(image_base64)
|
||||
except Exception:
|
||||
image_data = open(os.path.join(http.addons_manifest['web']['addons_path'], 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
|
||||
|
||||
headers.append(('ETag', retag))
|
||||
headers.append(('Content-Length', len(image_data)))
|
||||
try:
|
||||
ncache = int(kw.get('cache'))
|
||||
headers.append(('Cache-Control', 'no-cache' if ncache == 0 else 'max-age=%s' % (ncache)))
|
||||
except:
|
||||
pass
|
||||
return request.make_response(image_data, headers)
|
||||
|
||||
@http.route(['/website/publish/'], type='http', auth="public")
|
||||
def publish(self, **post):
|
||||
_id = int(post['id'])
|
||||
|
|
|
@ -408,7 +408,9 @@
|
|||
<span>&#x2706; <span t-field="res_company.phone"></span></span><br/>
|
||||
<i class="icon-envelope"></i> <span t-field="res_company.email"></span>
|
||||
</address>
|
||||
<img class="thumbnail" t-att-src="google_map_url"/>
|
||||
<a t-att-href="res_company.partner_id.google_map_link()" target="_BLANK">
|
||||
<img class="thumbnail" t-att-src="res_company.partner_id.google_map_img()"/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -24,7 +24,7 @@ def urlplus(url, params):
|
|||
return url
|
||||
url += "?"
|
||||
for k,v in params.items():
|
||||
url += "%s=%s&" % (k, urllib.quote_plus(v))
|
||||
url += "%s=%s&" % (k, urllib.quote_plus(str(v)))
|
||||
return url
|
||||
|
||||
|
||||
|
|
|
@ -103,7 +103,6 @@ class website_event(http.Controller):
|
|||
event = request.registry['event.event'].browse(request.cr, request.uid, event_id, {'show_address': 1})
|
||||
values = website.get_rendering_context({
|
||||
'event_id': event,
|
||||
'google_map_url': "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=12&size=298x298" % urllib.quote_plus('%s, %s %s, %s' % (event.street, event.city, event.zip, event.country_id and event.country_id.name_get()[0][1] or ''))
|
||||
})
|
||||
return website.render("website_event.detail", values)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from openerp.osv import osv, fields
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
# defined for access rules
|
||||
class product(osv.osv):
|
||||
|
@ -9,3 +10,16 @@ class product(osv.osv):
|
|||
'event_ticket_ids': fields.one2many('event.event.ticket', 'product_id', 'Event Tickets'),
|
||||
}
|
||||
|
||||
|
||||
class event_event(osv.osv):
|
||||
_inherit = "event.event"
|
||||
|
||||
def google_map_img(self, cr, uid, ids, zoom=8, width=298, height=298, context=None):
|
||||
partner = self.browse(cr, uid, ids[0], context=context)
|
||||
if partner.address_id:
|
||||
return self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_img()
|
||||
|
||||
def google_map_link(self, cr, uid, ids, zoom=8, context=None):
|
||||
partner = self.browse(cr, uid, ids[0], context=context)
|
||||
if partner.address_id:
|
||||
return self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_link()
|
||||
|
|
|
@ -112,14 +112,16 @@
|
|||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
<script type="text/javascript" src="/website_event/static/src/js/website_event.js"></script>
|
||||
<t t-raw="head"/>
|
||||
<t t-raw="head or ''"/>
|
||||
</t>
|
||||
<t t-set="title">Events</t>
|
||||
<div class="container mt48">
|
||||
<div class="row">
|
||||
<div class="span4 css_noprint">
|
||||
<h4>When & Where</h4>
|
||||
<img t-att-src="google_map_url"/>
|
||||
<a t-att-href="event_id.google_map_link()" target="_BLANK">
|
||||
<img class="thumbnail" t-att-src="event_id.google_map_img()"/>
|
||||
</a>
|
||||
<address>
|
||||
<pre t-field="event_id.address_id"/>
|
||||
<i class="icon-time"></i> <span t-field="event_id.date_begin"> </span><br/>
|
||||
|
|
|
@ -9,3 +9,5 @@ class hr(osv.osv):
|
|||
'website_published': fields.boolean('Available in the website'),
|
||||
}
|
||||
|
||||
def img(self, cr, uid, ids, field='image_small', context=None):
|
||||
return "/website/image?model=%s&field=%s&id=%s" % (self._name, field, ids[0])
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<div t-foreach="employee_ids" t-as="employee_id" class="span4 mt16">
|
||||
<div class="media thumbnail">
|
||||
<a class="pull-left" href="#">
|
||||
<img class="media-object" t-att-src="'data:image/png;base64,%%s' %% employee_id.image_small"/>
|
||||
<img class="media-object" t-att-src="employee_id.img('image_small')"/>
|
||||
</a>
|
||||
<div class="media-body">
|
||||
<t t-call="website.publish"><t t-set="object" t-value="employee_id"/></t>
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
<h5 t-field="product.name"> </h5>
|
||||
</a>
|
||||
<a t-att-href="'/shop/product/%%s/' %% product.id">
|
||||
<img class="img-rounded" t-att-src="'data:image/png;base64,' + product.image"/>
|
||||
<img class="img-rounded" t-att-src="product.img('image_small')"/>
|
||||
</a>
|
||||
<div>
|
||||
<div t-field="product.description_sale"></div>
|
||||
|
@ -144,7 +144,7 @@
|
|||
<div class="oe_button_cart">
|
||||
<a t-att-href="'./add_cart/%s/' % product.id" class="btn btn-small btn-success">Add to cart</a>
|
||||
</div>
|
||||
<img class="media-object" t-att-src="'data:image/png;base64,' + product.image"/>
|
||||
<img class="media-object" t-att-src="product.img('image')"/>
|
||||
<div t-field="product.description_website"></div>
|
||||
<div class="oe_website_sale_price"><t t-field="product.list_price" />€</div>
|
||||
</div>
|
||||
|
@ -160,7 +160,7 @@
|
|||
<div class='span2 thumbnail'>
|
||||
<a t-att-href="'/shop/product/%%s/' %% product.id">
|
||||
<div class='mt16 text-center'>
|
||||
<img t-att-src="'data:image/png;base64,' + product.image"/>
|
||||
<img t-att-src="product.img('image_small')"/>
|
||||
<h5 t-field='product.name'></h5>
|
||||
</div>
|
||||
</a>
|
||||
|
@ -195,7 +195,7 @@
|
|||
<t t-foreach="order.order_line" t-as="line">
|
||||
<tr>
|
||||
<td>
|
||||
<a t-att-href="'/shop/product/%%s/' %% line.product_id"><img class="img-rounded" t-att-src="'data:image/png;base64,' + line.product_id.image"/></a>
|
||||
<a t-att-href="'/shop/product/%%s/' %% line.product_id"><img class="img-rounded" t-att-src="line.product_id.img('image_small')"/></a>
|
||||
</td>
|
||||
<td>
|
||||
<a t-att-href="'/shop/product/%%s/' %% line.product_id"><span t-field="line.product_id.name"/></a><br/>
|
||||
|
|
|
@ -57,6 +57,8 @@ class product_product(osv.osv):
|
|||
product_ids = self.search(cr, uid, [("id", "in", product_ids)])
|
||||
return self.browse(cr, uid, product_ids)
|
||||
|
||||
def img(self, cr, uid, ids, field='image_small', context=None):
|
||||
return "/website/image?model=%s&field=%s&id=%s" % (self._name, field, ids[0])
|
||||
|
||||
class sale_order(osv.osv):
|
||||
_inherit = "sale.order"
|
||||
|
|
Loading…
Reference in New Issue