[MERGE] Merge parents

bzr revid: rim@openerp.com-20131024145711-8m3t0n2iufpc15bx
This commit is contained in:
Richard Mathot (OpenERP)
2013-10-24 16:57:11 +02:00
10 changed files with 76 additions and 69 deletions
+23 -35
View File
@@ -51,8 +51,7 @@ class Website(openerp.addons.web.controllers.main.Home):
def index(self, **kw):
return self.page("website.homepage")
# FIXME: auth, if /pagenew known anybody can create new empty page
@website.route('/pagenew/<path:path>', type='http', auth="admin")
@website.route('/pagenew/<path:path>', type='http', auth="user")
def pagenew(self, path, noredirect=NOPE):
module = 'website'
# completely arbitrary max_length
@@ -215,11 +214,9 @@ class Website(openerp.addons.web.controllers.main.Home):
'value': new_content,
}
irt.create(request.cr, request.uid, new_trans)
irt._get_source.clear_cache(irt) # FIXME: find why ir.translation does not invalidate
return True
# # FIXME: auth, anybody can upload an attachment if URL known/found
@website.route('/website/attach', type='http', auth='admin')
@website.route('/website/attach', type='http', auth='user')
def attach(self, func, upload):
req = request.httprequest
if req.method != 'POST':
@@ -229,12 +226,18 @@ class Website(openerp.addons.web.controllers.main.Home):
try:
attachment_id = request.registry['ir.attachment'].create(request.cr, request.uid, {
'name': upload.filename,
'datas': base64.encodestring(upload.read()),
'datas': upload.read().encode('base64'),
'datas_fname': upload.filename,
'res_model': 'ir.ui.view',
}, request.context)
# FIXME: auth=user... no good.
url = '/website/attachment/%d' % attachment_id
url = website.urlplus('/website/image', {
'model': 'ir.attachment',
'id': attachment_id,
'field': 'datas',
'max_height': MAX_IMAGE_HEIGHT,
'max_width': MAX_IMAGE_WIDTH,
})
except Exception, e:
logger.exception("Failed to upload image to attachment")
message = str(e)
@@ -283,7 +286,7 @@ class Images(http.Controller):
return response.make_conditional(request.httprequest)
@website.route('/website/image', auth="public")
def image(self, model, id, field):
def image(self, model, id, field, max_width=maxint, max_height=maxint):
Model = request.registry[model]
response = werkzeug.wrappers.Response()
@@ -291,7 +294,7 @@ class Images(http.Controller):
id = int(id)
ids = Model.search(request.cr, request.uid,
[('id', '=', id)], context=request.context)\
[('id', '=', id)], context=request.context) \
or Model.search(request.cr, openerp.SUPERUSER_ID,
[('id', '=', id), ('website_published', '=', True)], context=request.context)
@@ -312,8 +315,8 @@ class Images(http.Controller):
response.last_modified = datetime.datetime.strptime(
record[concurrency], server_format)
# Field does not exist on model or field set to False
if not record.get(field):
# Field does not exist on model or field set to False
# FIXME: maybe a field which does not exist should be a 404?
return self.placeholder(response)
@@ -324,31 +327,13 @@ class Images(http.Controller):
if response.status_code == 304:
return response
return self.set_image_data(response, record[field].decode('base64'))
data = record[field].decode('base64')
fit = int(max_width), int(max_height)
# FIXME: auth
# FIXME: delegate to image?
@website.route('/website/attachment/<int:id>', auth='admin')
def attachment(self, id):
attachment = request.registry['ir.attachment'].browse(
request.cr, request.uid, id, request.context)
return self.set_image_data(
werkzeug.wrappers.Response(),
attachment.datas.decode('base64'),
fit=IMAGE_LIMITS,)
def set_image_data(self, response, data, fit=(maxint, maxint)):
""" Sets an inferred mime type on the response object, and puts the
provided image's data in it, possibly after resizing if requested
Returns the response object after setting its mime and content, so
the result of ``get_final_image`` can be returned directly.
"""
buf = cStringIO.StringIO(data)
# FIXME: unknown format or not an image
image = Image.open(buf)
image.load()
response.mimetype = Image.MIME[image.format]
w, h = image.size
@@ -356,10 +341,13 @@ class Images(http.Controller):
if w < max_w and h < max_h:
response.set_data(data)
return response
else:
image.thumbnail(fit, Image.ANTIALIAS)
image.save(response.stream, image.format)
# invalidate content-length computed by make_conditional as writing
# to response.stream does not do it (as of werkzeug 0.9.3)
del response.headers['Content-Length']
image.thumbnail(fit, Image.ANTIALIAS)
image.save(response.stream, image.format)
return response
+5 -3
View File
@@ -12,6 +12,7 @@ import itertools
import logging
import re
import urllib2
import urlparse
import werkzeug.utils
from dateutil import parser
@@ -199,10 +200,11 @@ class Image(orm.AbstractModel):
def from_html(self, cr, uid, model, column, element, context=None):
url = element.find('img').get('src')
m = re.match(r'^/website/attachment/(\d+)$', url)
if m:
url_object = urlparse.urlsplit(url)
query = urlparse.parse_qs(url_object.query)
if url_object.path == '/website/image' and query['model'] == 'ir.attachment':
attachment = self.pool['ir.attachment'].browse(
cr, uid, int(m.group(1)), context=context)
cr, uid, int(query['id']), context=context)
return attachment.datas
# remote URL?
+8 -3
View File
@@ -364,13 +364,18 @@ class website(osv.osv):
class ir_attachment(osv.osv):
_inherit = "ir.attachment"
def _website_url_get(self, cr, uid, ids, name, arg, context=None):
context = context or {}
result = {}
for attach in self.browse(cr, uid, ids, context=context):
if attach.type=='url':
if attach.type == 'url':
result[attach.id] = attach.url
else:
result[attach.id] = "/website/attachment/"+str(attach.id)
result[attach.id] = urlplus('/website/image', {
'model': 'ir.attachment',
'field': 'datas',
'id': attach.id,
'max_width': 1024,
'max_height': 768,
})
return result
_columns = {
'website_url': fields.function(_website_url_get, string="Attachment URL", type='char')
@@ -25,8 +25,8 @@
save: function () {
this.snippets.make_active(false);
// TODO TOFIX: call clean_for_save on all snippets of the page, not only modified ones
// important for banner of parallax that changes data automatically.
// FIXME: call clean_for_save on all snippets of the page, not only modified ones
// important for banner of parallax that changes data automatically.
this.snippets.clean_for_save();
remove_added_snippet_id();
this._super();
+18 -17
View File
@@ -226,23 +226,24 @@
<template id="publish_management">
<t t-if="editable" t-ignore="true">
<div class="pull-right btn-group">
<div t-attf-class="btn-group dropdown js_publish_management #{object.id and object.website_published and 'css_publish' or 'css_unpublish'}" t-att-data-id="object.id" t-att-data-object="object._name">
<a t-attf-class="btn btn-xs btn-#{object.id and object.website_published and 'success' or 'default'}" t-att-id="'dopprod-%s' % object.id" role="button" data-toggle="dropdown">Options <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" t-att-aria-labelledby="'dopprod-%s' % object.id">
<t t-raw="0"/>
<li>
<a href="#" class="js_publish_btn css_unpublish">Unpublish</a>
<a href="#" class="js_publish_btn css_publish">Publish</a>
</li>
<li t-if="publish_duplicate">
<a t-att-href="publish_duplicate">Duplicate</a>
</li>
</ul>
</div>
<t t-if="publish_edit">
<a class="btn btn-xs btn-default" title="Edit in backend" t-att-href="'/web#model=%s&amp;id=%s' % (object._name, object.id)"><span t-attf-class="glyphicon glyphicon-wrench"></span></a>
</t>
<div class="pull-right">
<div t-attf-class="btn-group dropdown js_publish_management #{object.id and object.website_published and 'css_publish' or 'css_unpublish'}" t-att-data-id="object.id" t-att-data-object="object._name">
<a t-attf-class="btn btn-sm btn-#{object.id and object.website_published and 'success' or 'default'}" t-att-id="'dopprod-%s' % object.id" role="button" data-toggle="dropdown">Options <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" t-att-aria-labelledby="'dopprod-%s' % object.id">
<t t-raw="0"/>
<li>
<a href="#" class="js_publish_btn css_unpublish">Unpublish</a>
<a href="#" class="js_publish_btn css_publish">Publish</a>
</li>
<li t-if="publish_duplicate">
<a t-att-href="publish_duplicate">Duplicate</a>
</li>
<li t-if="publish_edit">
<a t-att-href="'/web#model=%s&amp;id=%s' % (object._name, object.id)"
title='Edit in backend'>Edit</a>
</li>
</ul>
</div>
</div>
</t>
</template>
+1 -1
View File
@@ -79,7 +79,7 @@ class BlogPost(osv.Model):
'oe_expand_container_tag': 'div',
'oe_expand_container_class': 'oe_mail_expand text-center',
'oe_expand_container_content': '',
'oe_expand_a_href': '/blog/%d/%d' % (page.category_id.id, page.id),
'oe_expand_a_href': '/blog/%d/' % page.id,
'oe_expand_a_class': 'oe_mail_expand btn btn-info',
'oe_expand_separator_node': 'br',
},
@@ -256,7 +256,7 @@
through your <b>blog entries</b>, referenced in Google.
</p>
<div>
<button src="/contactus" class="btn btn-primary">Contact us</button>
<a t-href="/page/website.contactus"><button class="btn btn-primary">Contact us</button></a>
</div>
</section>
</xpath>
+5 -1
View File
@@ -113,7 +113,7 @@ class Ecommerce(http.Controller):
request.context['pricelist'] = self.get_pricelist()
# search for checking of access rules and keep order
product_ids = [id for id in product_ids if id in product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)]
product_ids = product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)
size_ids = {}
style_ids = style_obj.search(request.cr, SUPERUSER_ID, [('html_class', 'like', 'size_%')], context=request.context)
@@ -212,6 +212,7 @@ class Ecommerce(http.Controller):
col += 1
line += 1
print bin_packing_list
return bin_packing_list
def get_products(self, product_ids):
@@ -272,6 +273,9 @@ class Ecommerce(http.Controller):
@website.route(['/shop/', '/shop/page/<int:page>/'], type='http', auth="public", multilang=True)
def category(self, category=0, attributes="", page=0, **post):
# TDE-NOTE: shouldn't we do somethign about product_template without variants ???
# TDE-NOTE: is there a reason to call a method category when the route is
# basically a shop without category_id speceified ?
if 'promo' in post:
self.change_pricelist(post.get('promo'))
+11 -4
View File
@@ -35,10 +35,17 @@ class product_template(osv.Model):
_name = 'product.template'
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = {}
""" TDE-NOTE: as someone wrote this method without any clue on about what it
does, fixing bugs about product_variant_ids not existing will be done
based on the weather, the sun and Lilo's feelings about pigs.
If you see this comment in trunk, this means that the website branch has
been merged without any review, which is quite questionable. """
res = dict.fromkeys(ids, '')
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
for prod in self.browse(cr, uid, ids, context=context):
res[prod.id] = "%s/shop/product/%s/" % (base_url, prod.product_variant_ids[0].id)
for product in self.browse(cr, uid, ids, context=context):
if product.product_variant_ids:
res[product.id] = "%s/shop/product/%s/" % (base_url, product.product_variant_ids[0].id)
return res
_columns = {
@@ -48,7 +55,7 @@ class product_template(osv.Model):
'suggested_product_ids': fields.one2many('product.template', 'suggested_product_id', 'Suggested Products'),
'website_size_x': fields.integer('Size X'),
'website_size_y': fields.integer('Size Y'),
'website_style_ids' : fields.many2many('website.product.style','product_website_style_rel', 'product_id', 'style_id', 'Styles'),
'website_style_ids': fields.many2many('website.product.style', 'product_website_style_rel', 'product_id', 'style_id', 'Styles'),
'website_sequence': fields.integer('Sequence', help="Determine the display order in the Website E-commerce"),
'website_url': fields.function(_website_url, string="Website url"),
}
+2 -2
View File
@@ -43,7 +43,7 @@
<b t-field="product.name"/>
</a>
</div>
<div class="product_price">
<div class="product_price" t-if="product.product_variant_ids">
<b>
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
<del class="text-danger"
@@ -285,7 +285,7 @@
<br/>
</t>
<div class="product_price mt16">
<div class="product_price mt16" t-if="product.product_variant_ids">
<h4>
<b><span class="oe_price" t-esc="product.product_variant_ids[0].price" /> €</b>