def record_to_html(self, cr, uid, field_name, record, options=None, context=None): if options is None: options = {} aclasses = ['img', 'img-responsive'] + options.get('class', '').split() classes = ' '.join(itertools.imap(escape, aclasses)) max_size = None max_width, max_height = options.get('max_width', 0), options.get('max_height', 0) if max_width or max_height: max_size = '%sx%s' % (max_width, max_height) src = self.pool['ir.attachment'].image_url(cr, uid, record, field_name, max_size) if options.get('resize'): src = "%s/%s" % (src, options.get('resize')) img = '<img class="%s" src="%s" style="%s"/>' % ( classes, src, options.get('style', '')) return ir_qweb.HTMLSafe(img)
def record_to_html(self, cr, uid, field_name, record, options=None, context=None): if options is None: options = {} aclasses = ['img', 'img-responsive'] + options.get('class', '').split() classes = ' '.join(itertools.imap(escape, aclasses)) max_size = None if options.get('resize'): max_size = options.get('resize') else: max_width, max_height = options.get('max_width', 0), options.get('max_height', 0) if max_width or max_height: max_size = '%sx%s' % (max_width, max_height) sha = hashlib.sha1(getattr(record, '__last_update')).hexdigest()[0:7] max_size = '' if max_size is None else '/%s' % max_size src = '/web/image/%s/%s/%s%s?unique=%s' % (record._name, record.id, field_name, max_size, sha) alt = None if options.get('alt-field') and getattr(record, options['alt-field'], None): alt = record[options['alt-field']] elif options.get('alt'): alt = options['alt'] img = '<img class="%s" src="%s" style="%s"%s/>' % \ (classes, src, options.get('style', ''), ' alt="%s"' % alt if alt else '') return ir_qweb.HTMLSafe(img)
def record_to_html(self, cr, uid, field_name, record, options=None, context=None): if options is None: options = {} fields = options.get('fields') or ["longitude", "latitude"] if context is None: context = {} value_rec = record[field_name] if not value_rec: return None value_rec = value_rec.sudo().with_context(show_map=True) val = { 'longitude': value_rec.longitude, 'latitude': value_rec.latitude, 'fields': fields, 'object': value_rec, 'options': options } html = self.pool["ir.ui.view"].render(cr, uid, "odoo_extension.map", val, engine='ir.qweb', context=context).decode('utf8') return ir_qweb.HTMLSafe(html)
def record_to_html(self, cr, uid, field_name, record, options=None, context=None): if options is None: options = {} aclasses = ['img', 'img-responsive'] + options.get('class', '').split() classes = ' '.join(itertools.imap(escape, aclasses)) max_size = None max_width, max_height = options.get('max_width', 0), options.get('max_height', 0) if max_width or max_height: max_size = '%sx%s' % (max_width, max_height) src = self.pool['website'].image_url(cr, uid, record, field_name, max_size) alt = None if options.get('alt-field') and getattr(record, options['alt-field'], None): alt = escape(record[options['alt-field']]) elif options.get('alt'): alt = options['alt'] img = '<img class="%s" src="%s" style="%s"%s/>' % ( classes, src, options.get('style', ''), ' alt="%s"' % alt if alt else '') return ir_qweb.HTMLSafe(img)
def record_to_html(self, cr, uid, field_name, record, column, options=None, context=None): if options is None: options = {} classes = ['img', 'img-responsive'] + options.get('class', '').split() url_frags = { 'classes': ' '.join(itertools.imap(escape, classes)), 'model': record._model._name, 'id': record.id, 'field': field_name, 'max_size': '', } max_width, max_height = options.get('max_width', 0), options.get('max_height', 0) if max_width or max_height: url_frags['max_size'] = '/%sx%s' % (max_width, max_height) img = '<img class="%(classes)s" src="/website/image/%(model)s/%(id)s/%(field)s%(max_size)s"/>' return ir_qweb.HTMLSafe(img % url_frags)
def record_to_html(self, cr, uid, field_name, record, column, options=None, context=None): opf = options.get('fields') or [ "name", "address", "phone", "mobile", "fax", "email" ] if not getattr(record, field_name): return None id = getattr(record, field_name).id field_browse = self.pool[column._obj].browse( cr, openerp.SUPERUSER_ID, id, context={"show_address": True}) value = werkzeug.utils.escape(field_browse.name_get()[0][1]) val = { 'name': value.split("\n")[0], 'address': werkzeug.utils.escape("\n".join(value.split("\n")[1:])), 'phone': field_browse.phone, 'mobile': field_browse.mobile, 'fax': field_browse.fax, 'city': field_browse.city, 'country_id': field_browse.country_id and field_browse.country_id.name_get()[0][1], 'email': field_browse.email, 'fields': opf, 'options': options } html = self.pool["ir.ui.view"].render(cr, uid, "website.contact", val, engine='website.qweb', context=context).decode('utf8') return ir_qweb.HTMLSafe(html)
def record_to_html(self, cr, uid, field_name, record, column, options=None, context=None): if options is None: options = {} classes = ['img', 'img-responsive'] + options.get('class', '').split() return ir_qweb.HTMLSafe( '<img class="%s" src="/website/image?model=%s&field=%s&id=%s"/>' % (' '.join(itertools.imap(werkzeug.utils.escape, classes)), record._model._name, field_name, record.id))
def record_to_html(self, cr, uid, field_name, record, column, options=None, context=None): if options is None: options = {} classes = ['img', 'img-responsive'] + options.get('class', '').split() url_params = { 'model': record._model._name, 'field': field_name, 'id': record.id, } for options_key in ['max_width', 'max_height']: if options.get(options_key): url_params[options_key] = options[options_key] return ir_qweb.HTMLSafe('<img class="%s" src="/website/image?%s"/>' % ( ' '.join(itertools.imap(escape, classes)), werkzeug.urls.url_encode(url_params) ))
def _format(self, inner, options, qwebcontext): engine = self.pool["ir.qweb"] object = engine.eval(inner, qwebcontext) fields = options['fields'] val = { 'longitude': object[fields[0]], 'latitude': object[fields[1]], 'fields': fields, 'object': object, 'options': options } qwebcontext.update(val) html = engine.render(object.env.cr, object.env.uid, "odoo_extension.map", qwebcontext=qwebcontext, context=val).decode('utf8') return ir_qweb.HTMLSafe(html)