def nl2br(string, options=None): """ Converts newlines to HTML linebreaks in ``string``. Automatically escapes content unless options['html-escape'] is set to False, and returns the result wrapped in an HTMLSafe object. :param str string: :param dict options: :rtype: HTMLSafe """ if options is None: options = {} html_escape = options.get('html-escape', True) #html escape True by default richtext = options.get('richtext', False) #display rich text #escape if html_escape and not richtext: string = escape(string) #replace if richtext: string = string.replace('\n', '') else: string = string.replace('\n', '<br>\n') return HTMLSafe(string)
def value_to_html(self, cr, uid, value, field, options=None, context=None): barcode_type = options.get('type', 'Code128') barcode = self.pool['report'].barcode( barcode_type, value, **dict((key, value) for key, value in list(options.items()) if key in ['width', 'height', 'humanreadable'])) return HTMLSafe('<img src="data:%s;base64,%s">' % ('png', barcode.encode('base64')))
def _format(self, inner, options, qwebcontext): if options is None: options = {} record = self.pool['ir.qweb'].eval(inner, qwebcontext) domain = [] if options.get('domain', False): domain += options.get('domain') template = options.get('template', 'solt_qweb_widgets.website_partners') partner_obj = self.pool.get('res.partner') url = "/partners" partner_count = partner_obj.search_count(qwebcontext.cr, SUPERUSER_ID, domain) pager = record.pager(url=url, total=partner_count, page=0, step=PPG, scope=7, url_args={}) partner_ids = partner_obj.search( qwebcontext.cr, SUPERUSER_ID, domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc') partners = partner_obj.browse(qwebcontext.cr, SUPERUSER_ID, partner_ids) category_obj = self.pool['res.partner.category'] category_ids = category_obj.search(qwebcontext.cr, SUPERUSER_ID, [('parent_id', '=', False)]) categs = category_obj.browse(qwebcontext.cr, SUPERUSER_ID, category_ids) keep = QueryURL('/') values = { 'search': '', 'category': None, 'pager': pager, 'partners': partners, 'bins': table_compute().process(partners), 'rows': PPR, 'PPG': PPG, 'categories': categs, 'keep': keep, } html = self.pool["ir.ui.view"].render(qwebcontext.cr, SUPERUSER_ID, template, values, engine='ir.qweb').decode('utf8') return HTMLSafe(html)
def record_to_html(self, cr, uid, field_name, record, options=None, context=None): if context is None: context = {} if options is None: options = {} opf = options.get('fields') or [ "name", "address", "phone", "mobile", "fax", "email" ] value_rec = record[field_name] if not value_rec: return None value_rec = value_rec.sudo().with_context(show_address=True) value = value_rec.name_get()[0][1] val = { 'name': value.split("\n")[0], 'address': escape(" ".join(value.split("\n")[1:])), 'phone': value_rec.phone, 'mobile': value_rec.mobile, 'fax': value_rec.fax, 'city': value_rec.city, 'country_id': value_rec.country_id.display_name, 'website': value_rec.website, 'email': value_rec.email, 'vat': value_rec.vat, 'fields': opf, 'object': value_rec, 'options': options } val['address'] = val['address'].replace(val['country_id'], '') html = self.pool["ir.ui.view"].render(cr, uid, "base.contact", val, engine='ir.qweb', context=context).decode('utf8') return HTMLSafe(html)
def record_to_html(self, cr, uid, field_name, record, options, context=None): if context is None: context = {} Currency = self.pool['res.currency'] display_currency = self.display_currency(cr, uid, options['display_currency'], options) # lang.format mandates a sprintf-style format. These formats are non- # minimal (they have a default fixed precision instead), and # lang.format will not set one by default. currency.round will not # provide one either. So we need to generate a precision value # (integer > 0) from the currency's rounding (a float generally < 1.0). # # The log10 of the rounding should be the number of digits involved if # negative, if positive clamp to 0 digits and call it a day. # nb: int() ~ floor(), we want nearest rounding instead precision = int(math.floor(math.log10(display_currency.rounding))) if options.get('no_rounding', False): precision = 0 fmt = "%.{0}f".format(-precision if precision < 0 else 0) from_amount = record[field_name] if options.get('from_currency'): from_currency = self.display_currency(cr, uid, options['from_currency'], options) from_amount = Currency.compute(cr, uid, from_currency.id, display_currency.id, from_amount) lang_code = context.get('lang') or 'en_US' lang = self.pool['res.lang'] formatted_amount = lang.format(cr, uid, [lang_code], fmt, Currency.round(cr, uid, display_currency, from_amount), grouping=True, monetary=True) pre = post = u'' if display_currency.position == 'before': pre = u'{symbol}\N{NO-BREAK SPACE}' else: post = u'\N{NO-BREAK SPACE}{symbol}' return HTMLSafe(u'{pre}<span class="oe_currency_value">{0}</span>{post}'.format( formatted_amount, pre=pre, post=post, ).format( symbol=display_currency.symbol, ))
def record_to_html(self, cr, uid, field_name, record, options=None, context=None): if context is None: context = {} html = self.pool["ir.ui.view"].render( cr, uid, "website_countdown.front_countdown", { 'countdown_date': record[field_name], 'options': options }, engine='ir.qweb', context=context).decode('utf8') return HTMLSafe(html)
def _format(self, inner, options, qwebcontext): product = qwebcontext.get('product') category = '' search = '' cr, uid, context, pool = qwebcontext.cr, SUPERUSER_ID, qwebcontext.context, self.pool category_obj = pool['product.public.category'] template_obj = pool['product.template'] context.update(active_id=product.id) if category: category = category_obj.browse(cr, uid, int(category), context=context) # attrib_list = request.httprequest.args.getlist('attrib') # attrib_values = [map(int,v.split("-")) for v in attrib_list if v] # attrib_set = set([v[1] for v in attrib_values]) keep = QueryURL('/shop', category=category and category.id, search=search, attrib=[]) #attrib_list category_ids = category_obj.search(cr, uid, [], context=context) category_list = category_obj.name_get(cr, uid, category_ids, context=context) category_list = sorted(category_list, key=lambda category: category[1]) pricelist = get_pricelist() from_currency = pool.get('product.price.type')._get_field_currency( cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute( cr, uid, from_currency, to_currency, price, context=context) if not request.context.get('pricelist'): request.context['pricelist'] = int(get_pricelist()) product = template_obj.browse(cr, uid, int(product), context=context) values = { 'search': search, 'category': category, 'pricelist': pricelist, 'attrib_values': [], #attrib_values, 'compute_currency': compute_currency, 'attrib_set': set(), #attrib_set, 'keep': keep, 'category_list': category_list, 'main_object': product, 'product': product, 'get_attribute_value_ids': self.get_attribute_value_ids } qwebcontext.update(values) html = pool["ir.qweb"].render_node(inner, qwebcontext).decode('utf8') return HTMLSafe(html)
def _format(self, inner, options, qwebcontext): if options is None: options = {} record = self.pool['ir.qweb'].eval(inner, qwebcontext) domain = [] if options.get('domain', False): domain += options.get('domain') template = options.get('template', 'solt_qweb_widgets.website_products') product_obj = self.pool.get('product.template') url = "/shop" product_count = product_obj.search_count(qwebcontext.cr, SUPERUSER_ID, domain) pager = record.pager(url=url, total=product_count, page=0, step=PPG, scope=7, url_args={}) product_ids = product_obj.search( qwebcontext.cr, SUPERUSER_ID, domain, limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc') products = product_obj.browse(qwebcontext.cr, SUPERUSER_ID, product_ids) style_obj = self.pool['product.style'] style_ids = style_obj.search(qwebcontext.cr, SUPERUSER_ID, []) styles = style_obj.browse(qwebcontext.cr, SUPERUSER_ID, style_ids) category_obj = self.pool['product.public.category'] category_ids = category_obj.search(qwebcontext.cr, SUPERUSER_ID, [('parent_id', '=', False)]) categs = category_obj.browse(qwebcontext.cr, SUPERUSER_ID, category_ids) attributes_obj = self.pool['product.attribute'] attributes_ids = attributes_obj.search(qwebcontext.cr, SUPERUSER_ID, []) attributes = attributes_obj.browse(qwebcontext.cr, SUPERUSER_ID, attributes_ids) partner = self.pool['res.users'].browse(qwebcontext.cr, SUPERUSER_ID, SUPERUSER_ID).partner_id pricelist = partner.property_product_pricelist from_currency = self.pool.get( 'product.price.type')._get_field_currency(qwebcontext.cr, SUPERUSER_ID, 'list_price', qwebcontext.context) to_currency = pricelist.currency_id compute_currency = lambda price: self.pool['res.currency']._compute( qwebcontext.cr, SUPERUSER_ID, from_currency, to_currency, price) keep = QueryURL('/shop') values = { 'search': '', 'category': None, 'attrib_values': [], 'attrib_set': set(), 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'PPG': PPG, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), } html = self.pool["ir.ui.view"].render(qwebcontext.cr, SUPERUSER_ID, template, values, engine='ir.qweb').decode('utf8') return HTMLSafe(html)