# NOTE: as the pattern is used as it for the ModelConverter (ir_http.py), do not use any flags
_UNSLUG_RE = re.compile(r'(?:(\w{1,2}|\w[A-Za-z0-9-_]+?\w)-)?(-?\d+)(?=$|/)')
+DEFAULT_CDN_FILTERS = [
+ "^/[^/]+/static/",
+ "^/web/(css|js)/",
+ "^/website/image/",
+]
+
def unslug(s):
"""Extract slug and id from a string.
Always return un 2-tuple (str|None, int|None)
'google_analytics_key': fields.char('Google Analytics Key'),
'user_id': fields.many2one('res.users', string='Public User'),
'compress_html': fields.boolean('Compress HTML'),
+ 'cdn_activated': fields.boolean('Activate CDN for assets'),
+ 'cdn_url': fields.char('CDN Base URL'),
+ 'cdn_filters': fields.text('CDN Filters', help="URL matching those filters will be rewritten using the CDN Base URL"),
'partner_id': fields.related('user_id','partner_id', type='many2one', relation='res.partner', string='Public Partner'),
'menu_id': fields.function(_get_menu, relation='website.menu', type='many2one', string='Main Menu')
}
'user_id': lambda self,cr,uid,c: self.pool['ir.model.data'].xmlid_to_res_id(cr, openerp.SUPERUSER_ID, 'base.public_user'),
'company_id': lambda self,cr,uid,c: self.pool['ir.model.data'].xmlid_to_res_id(cr, openerp.SUPERUSER_ID,'base.main_company'),
'compress_html': False,
+ 'cdn_activated': False,
+ 'cdn_url': '//localhost:8069/',
+ 'cdn_filters': '\n'.join(DEFAULT_CDN_FILTERS),
}
# cf. Wizard hack in website_views.xml
website = self.browse(cr, uid, id)
return [(lg.code, lg.name) for lg in website.language_ids]
+ def get_cdn_url(self, cr, uid, uri, context=None):
+ # Currently only usable in a website_enable request context
+ if request and request.website and not request.debug:
+ cdn_url = request.website.cdn_url
+ cdn_filters = (request.website.cdn_filters or '').splitlines()
+ for flt in cdn_filters:
+ if flt and re.match(flt, uri):
+ return urlparse.urljoin(cdn_url, uri)
+ return uri
+
def get_languages(self, cr, uid, ids, context=None):
return self._get_languages(cr, uid, ids[0], context=context)
ids = Model.search(cr, uid,
[('id', '=', id)], context=context)
- if not ids and 'website_published' in Model._all_columns:
+ if not ids and 'website_published' in Model._fields:
ids = Model.search(cr, openerp.SUPERUSER_ID,
[('id', '=', id), ('website_published', '=', True)], context=context)
if not ids:
response.data = data
else:
size = (max_w, max_h)
- img = image_resize_and_sharpen(image, size)
+ img = image_resize_and_sharpen(image, size, preserve_aspect_ratio=True)
image_save_for_web(img, response.stream, format=image.format)
# invalidate content-length computed by make_conditional as
# writing to response.stream does not do it (as of werkzeug 0.9.3)
result[attach.id] = self.pool['website'].image_url(cr, uid, attach, 'datas')
return result
def _datas_checksum(self, cr, uid, ids, name, arg, context=None):
- return dict(
- (attach['id'], self._compute_checksum(attach))
- for attach in self.read(
- cr, uid, ids, ['res_model', 'res_id', 'type', 'datas'],
- context=context)
- )
+ result = dict.fromkeys(ids, False)
+ attachments = self.read(cr, uid, ids, ['res_model'], context=context)
+ view_attachment_ids = [attachment['id'] for attachment in attachments if attachment['res_model'] == 'ir.ui.view']
+ for attach in self.read(cr, uid, view_attachment_ids, ['res_model', 'res_id', 'type', 'datas'], context=context):
+ result[attach['id']] = self._compute_checksum(attach)
+ return result
def _compute_checksum(self, attachment_dict):
if attachment_dict.get('res_model') == 'ir.ui.view'\
return result
for record in self.browse(cr, uid, ids, context=context):
- if not record.datas: continue
+ if record.res_model != 'ir.ui.view' or not record.datas: continue
try:
result[record.id] = openerp.tools.image_resize_image_big(record.datas)
except IOError: # apparently the error PIL.Image.open raises
'zoom': zoom,
'sensor': 'false',
}
- return urlplus('http://maps.googleapis.com/maps/api/staticmap' , params)
+ return urlplus('//maps.googleapis.com/maps/api/staticmap' , params)
def google_map_link(self, cr, uid, ids, zoom=8, context=None):
partner = self.browse(cr, uid, ids[0], context=context)