def _compute_kanban_subtasks_icons(self): for record in self: result_string1 = '' result_string2 = '' result_string3 = '' for subtask in record.subtask_ids: # Shorten Name bounding_length = 24 tmp_list = (subtask.name).split() for index in range(len(tmp_list)): if len(tmp_list[index]) > bounding_length: tmp_list[ index] = tmp_list[index][:bounding_length] + '...' tmp_subtask_name = " ".join(tmp_list) if subtask.state == 'todo' and record.env.user == subtask.user_id and record.env.user == subtask.reviewer_id: tmp_string3 = escape(u' {0}'.format(tmp_subtask_name)) result_string3 += u'<li><span class="fa fa-edit task-kanban-todo"></span>{}</li>'.format( tmp_string3) elif subtask.state == 'todo' and record.env.user == subtask.user_id: tmp_string1 = escape(u'{0} {1}'.format( subtask.reviewer_id.name, tmp_subtask_name)) result_string1 += u'<li><span class="fa fa-edit task-kanban-todo"></span> from {}</li>'.format( tmp_string1) elif subtask.state == 'todo' and record.env.user == subtask.reviewer_id: tmp_string2 = escape(u'{0} {1}'.format( subtask.user_id.name, tmp_subtask_name)) result_string2 += u'<li><span class="fa fa-edit task-kanban-todo"></span> for {}</li>'.format( tmp_string2) record.kanban_subtasks_icons = '<ul class="task-kanban-todo">' + result_string1 + result_string3 + result_string2 + '</ul>'
def google_map(self, *arg, **post): cr, uid, context = request.cr, request.uid, request.context partner_obj = request.registry["res.partner"] # filter real ints from query parameters and build a domain clean_ids = [] for s in post.get("partner_ids", "").split(","): try: i = int(s) clean_ids.append(i) except ValueError: pass # search for partners that can be displayed on a map domain = [("id", "in", clean_ids), ("website_published", "=", True), ("is_company", "=", True)] partners_ids = partner_obj.search(cr, SUPERUSER_ID, domain, context=context) # browse and format data partner_data = {"counter": len(partners_ids), "partners": []} request.context.update({"show_address": True}) for partner in partner_obj.browse(cr, SUPERUSER_ID, partners_ids, context=context): partner_data["partners"].append( { "id": partner.id, "name": escape(partner.name), "address": escape("\n".join(partner.name_get()[0][1].split("\n")[1:])), "latitude": escape(str(partner.partner_latitude)), "longitude": escape(str(partner.partner_longitude)), } ) # generate the map values = {"partner_url": post.get("partner_url"), "partner_data": json.dumps(partner_data)} return request.website.render("website_google_map.google_map", values)
def to_html(self, cr, uid, field_name, record, options, source_element, t_att, g_att, qweb_context, context=None): """ Converts a ``t-field`` to its HTML output. A ``t-field`` may be extended by a ``t-field-options``, which is a JSON-serialized mapping of configuration values. A default configuration key is ``widget`` which can override the field's own ``_type``. """ try: content = self.record_to_html( cr, uid, field_name, record, record._model._all_columns[field_name].column, options, context=context ) if options.get("html-escape", True): content = escape(content) elif hasattr(content, "__html__"): content = content.__html__() except Exception: _logger.warning("Could not get field %s for model %s", field_name, record._model._name, exc_info=True) content = None if context and context.get("inherit_branding"): # add branding attributes g_att += "".join( ' %s="%s"' % (name, escape(value)) for name, value in self.attributes( cr, uid, field_name, record, options, source_element, g_att, t_att, qweb_context ) ) return self.render_element(cr, uid, source_element, t_att, g_att, qweb_context, content)
def _compute_kanban_todolists(self): for record in self: result_string1 = '' result_string2 = '' result_string3 = '' for todo in record.todolist_ids: bounding_length = 25 tmp_list = (todo.name).split() for index in range(len(tmp_list)): if (len(tmp_list[index]) > bounding_length): tmp_list[ index] = tmp_list[index][:bounding_length] + '...' tmp_todo_name = " ".join(tmp_list) if todo.state == 'todo' and record.env.user == todo.user_id and record.env.user == todo.reviewer_id: tmp_string3 = escape(u': {0}'.format(tmp_todo_name)) result_string3 += u'<li><b>TODO</b>{}</li>'.format( tmp_string3) elif todo.state == 'todo' and record.env.user == todo.user_id: tmp_string1_1 = escape(u'{0}'.format( todo.reviewer_id.name)) tmp_string1_2 = escape(u'{0}'.format(tmp_todo_name)) result_string1 += u'<li><b>TODO</b> from <em>{0}</em>: {1}</li>'.format( tmp_string1_1, tmp_string1_2) elif todo.state == 'todo' and record.env.user == todo.reviewer_id: tmp_string2_1 = escape(u'{0}'.format(todo.user_id.name)) tmp_string2_2 = escape(u'{0}'.format(tmp_todo_name)) result_string2 += u'<li>TODO for <em>{0}</em>: {1}</li>'.format( tmp_string2_1, tmp_string2_2) record.kanban_todolists = '<ul>' + result_string1 + result_string3 + result_string2 + '</ul>'
def render_node(self, element, qwebcontext): result = "" if element.nodeType == self.node.TEXT_NODE or element.nodeType == self.node.CDATA_SECTION_NODE: result = element.data.encode("utf8") elif element.nodeType == self.node.ELEMENT_NODE: generated_attributes = "" t_render = None template_attributes = {} for (attribute_name, attribute_value) in element.attributes.items(): attribute_name = str(attribute_name) if attribute_name == "groups": cr = qwebcontext.get( 'request') and qwebcontext['request'].cr or None uid = qwebcontext.get( 'request') and qwebcontext['request'].uid or None can_see = self.user_has_groups( cr, uid, groups=attribute_value) if cr and uid else False if not can_see: return '' continue if isinstance(attribute_value, unicode): attribute_value = attribute_value.encode("utf8") else: attribute_value = attribute_value.nodeValue.encode("utf8") if attribute_name.startswith("t-"): for attribute in self._render_att: if attribute_name[2:].startswith(attribute): att, val = self._render_att[attribute]( self, element, attribute_name, attribute_value, qwebcontext) generated_attributes += val and ' %s="%s"' % ( att, escape(val)) or " " break else: if attribute_name[2:] in self._render_tag: t_render = attribute_name[2:] template_attributes[ attribute_name[2:]] = attribute_value else: generated_attributes += ' %s="%s"' % ( attribute_name, escape(attribute_value)) if 'debug' in template_attributes: debugger = template_attributes.get('debug', 'pdb') __import__(debugger).set_trace() # pdb, ipdb, pudb, ... if t_render: result = self._render_tag[t_render](self, element, template_attributes, generated_attributes, qwebcontext) else: result = self.render_element(element, template_attributes, generated_attributes, qwebcontext) if isinstance(result, unicode): return result.encode('utf-8') return result
def _get_pillar_data(self,clean_ids): cr, uid,context=request.cr,request.uid,request.context #code _get_pillar_data apl_obj=request.registry['uis.papl.apl'] pillar_data={ "counter":0, "latitude":0, "longitude":0, "pillars":[] } minlat=120 maxlat=0 minlong=120 maxlong=0 domain=[("id","in",clean_ids)] apl_ids=apl_obj.search(cr, uid, domain, context=context) for apl_id in apl_obj.browse(cr, uid, apl_ids, context=context): apl_id.pillar_id.sorted(key=lambda r: r.num_by_vl) for pillar_id in apl_id.pillar_id: #print "Do pillar"+pillar_id.name pillar_data["counter"]=pillar_data["counter"]+1 if pillar_id.latitude>maxlat: maxlat=pillar_id.latitude if pillar_id.latitude<minlat: minlat=pillar_id.latitude if pillar_id.longitude>maxlong: maxlong=pillar_id.longitude if pillar_id.longitude<minlong: minlong=pillar_id.longitude pillar_data["pillars"].append({ 'id':pillar_id.id, 'name':pillar_id.name, 'apl':apl_id.name, 'apl_id':apl_id.id, 'tap_id':pillar_id.tap_id.id, 'elevation':pillar_id.elevation, 'latitude': escape(str(pillar_id.latitude)), 'longitude': escape(str(pillar_id.longitude)), 'num_by_vl':pillar_id.num_by_vl, 'prev_id':pillar_id.parent_id.id, 'type_id':pillar_id.pillar_type_id.id, 'rotation':0, #Add direction pillar 'state':'EXPLOTATION' #Add state from MRO #'prevlatitude': escape(str(pillar_id.prev_latitude)), #'prevlangitude': escape(str(pillar_id.prev_longitude)) }) medlat=(maxlat+minlat)/2 medlong=(maxlong+minlong)/2 pillar_data["latitude"]=medlat pillar_data["longitude"]=medlong pillar_data["minlat"]=minlat pillar_data["maxlat"]=maxlat pillar_data["minlong"]=minlong pillar_data["maxlong"]=maxlong #end code _pillar_data return pillar_data
def google_map(self, *arg, **post): cr, uid, context = request.cr, request.uid, request.context partner_obj = request.registry['res.partner'] # filter real ints from query parameters and build a domain clean_ids = [] for s in post.get('partner_ids', "").split(","): try: i = int(s) clean_ids.append(i) except ValueError: pass # search for partners that can be displayed on a map domain = [("id", "in", clean_ids), ('website_published', '=', True), ('is_company', '=', True)] partners_ids = partner_obj.search(cr, SUPERUSER_ID, domain, context=context) # browse and format data partner_data = {"counter": len(partners_ids), "partners": []} request.context.update({'show_address': True}) for partner in partner_obj.browse(cr, SUPERUSER_ID, partners_ids, context=context): # TODO in master, do not use `escape` but `t-esc` in the qweb template. partner_data["partners"].append({ 'id': partner.id, 'name': escape(partner.name), 'address': escape('\n'.join(partner.name_get()[0][1].split('\n')[1:])), 'latitude': escape(str(partner.partner_latitude)), 'longitude': escape(str(partner.partner_longitude)), }) if 'customers' in post.get('partner_url', ''): partner_url = '/customers/' else: partner_url = '/partners/' google_maps_api_key = request.env['ir.config_parameter'].sudo( ).get_param('google_maps_api_key') # generate the map values = { 'partner_url': partner_url, 'partner_data': json.dumps(partner_data), 'google_maps_api_key': google_maps_api_key, } return request.website.render("website_google_map.google_map", values)
def _compile_directive_snippet(self, el, options): el.set('t-call', el.attrib.pop('t-snippet')) name = self.env['ir.ui.view'].search([ ('key', '=', el.attrib.get('t-call')) ]).display_name thumbnail = el.attrib.pop('t-thumbnail', "oe-thumbnail") div = u'<div name="%s" data-oe-type="snippet" data-oe-thumbnail="%s">' % ( escape(ir_qweb.unicodifier(name)), escape(ir_qweb.unicodifier(thumbnail))) return [self._append(ast.Str(div))] + self._compile_node( el, options) + [self._append(ast.Str(u'</div>'))]
def render_node(self, element, qwebcontext): result = "" if element.nodeType == self.node.TEXT_NODE or element.nodeType == self.node.CDATA_SECTION_NODE: result = element.data.encode("utf8") elif element.nodeType == self.node.ELEMENT_NODE: generated_attributes = "" t_render = None template_attributes = {} for (attribute_name, attribute_value) in element.attributes.items(): attribute_name = str(attribute_name) if attribute_name == "groups": cr = qwebcontext.get('request') and qwebcontext['request'].cr or None uid = qwebcontext.get('request') and qwebcontext['request'].uid or None can_see = self.user_has_groups(cr, uid, groups=attribute_value) if cr and uid else False if not can_see: if qwebcontext.get('editable') and not qwebcontext.get('editable_no_editor'): errmsg = _("Editor disabled because some content can not be seen by a user who does not belong to the groups %s") raise openerp.http.Retry( _("User does not belong to groups %s") % attribute_value, { 'editable_no_editor': errmsg % attribute_value }) return '' if isinstance(attribute_value, unicode): attribute_value = attribute_value.encode("utf8") else: attribute_value = attribute_value.nodeValue.encode("utf8") if attribute_name.startswith("t-"): for attribute in self._render_att: if attribute_name[2:].startswith(attribute): att, val = self._render_att[attribute](self, element, attribute_name, attribute_value, qwebcontext) generated_attributes += val and ' %s="%s"' % (att, escape(val)) or " " break else: if attribute_name[2:] in self._render_tag: t_render = attribute_name[2:] template_attributes[attribute_name[2:]] = attribute_value else: generated_attributes += ' %s="%s"' % (attribute_name, escape(attribute_value)) if 'debug' in template_attributes: debugger = template_attributes.get('debug', 'pdb') __import__(debugger).set_trace() # pdb, ipdb, pudb, ... if t_render: result = self._render_tag[t_render](self, element, template_attributes, generated_attributes, qwebcontext) else: result = self.render_element(element, template_attributes, generated_attributes, qwebcontext) if isinstance(result, unicode): return result.encode('utf-8') return result
def render_node(self, element, qwebcontext): result = "" if element.nodeType == self.node.TEXT_NODE or element.nodeType == self.node.CDATA_SECTION_NODE: result = element.data.encode("utf8") elif element.nodeType == self.node.ELEMENT_NODE: generated_attributes = "" t_render = None template_attributes = {} for (attribute_name, attribute_value) in element.attributes.items(): attribute_name = str(attribute_name) if attribute_name == "groups": cr = qwebcontext.get("request") and qwebcontext["request"].cr or None uid = qwebcontext.get("request") and qwebcontext["request"].uid or None can_see = self.user_has_groups(cr, uid, groups=attribute_value) if cr and uid else False if not can_see: return "" continue if isinstance(attribute_value, unicode): attribute_value = attribute_value.encode("utf8") else: attribute_value = attribute_value.nodeValue.encode("utf8") if attribute_name.startswith("t-"): for attribute in self._render_att: if attribute_name[2:].startswith(attribute): att, val = self._render_att[attribute]( self, element, attribute_name, attribute_value, qwebcontext ) generated_attributes += val and ' %s="%s"' % (att, escape(val)) or " " break else: if attribute_name[2:] in self._render_tag: t_render = attribute_name[2:] template_attributes[attribute_name[2:]] = attribute_value else: generated_attributes += ' %s="%s"' % (attribute_name, escape(attribute_value)) if "debug" in template_attributes: debugger = template_attributes.get("debug", "pdb") __import__(debugger).set_trace() # pdb, ipdb, pudb, ... if t_render: result = self._render_tag[t_render]( self, element, template_attributes, generated_attributes, qwebcontext ) else: result = self.render_element(element, template_attributes, generated_attributes, qwebcontext) if isinstance(result, unicode): return result.encode("utf-8") return result
def value_to_html(self, value, options): if not value.exists(): return False opf = options and options.get('fields') or [ "name", "address", "phone", "mobile", "fax", "email" ] value = value.sudo().with_context(show_address=True) name_get = value.name_get()[0][1] val = { 'name': name_get.split("\n")[0], 'address': escape("\n".join(name_get.split("\n")[1:])).strip(), 'phone': value.phone, 'mobile': value.mobile, 'fax': value.fax, 'city': value.city, 'country_id': value.country_id.display_name, 'website': value.website, 'email': value.email, 'fields': opf, 'object': value, 'options': options } return self.env['ir.qweb'].render('base.contact', val)
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 record_to_html(self, cr, uid, field_name, record, options=None, context=None): # necesitamos el valor de vat y formated_vat que no lo pasa a al val, por eso se hereda esta funcion 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("\n".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, 'formated_vat': value_rec.formated_vat(), 'fields': opf, 'object': value_rec, 'options': options } 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, record, field_name, options, values=None): opf = options and 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("\n".join(value.split("\n")[1:])).strip(), '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, 'fields': opf, 'object': value_rec, 'options': options } return unicodifier(self.env.ref('base.contact').render(val, engine='ir.qweb'))
def try_remove(self, cr, uid, ids, context=None): """ Removes a web-based image attachment if it is used by no view (template) Returns a dict mapping attachments which would not be removed (if any) mapped to the views preventing their removal """ Views = self.pool['ir.ui.view'] attachments_to_remove = [] # views blocking removal of the attachment removal_blocked_by = {} for attachment in self.browse(cr, uid, ids, context=context): # in-document URLs are html-escaped, a straight search will not # find them url = escape(attachment.website_url) ids = Views.search(cr, uid, [ "|", ('arch_db', 'like', '"%s"' % url), ('arch_db', 'like', "'%s'" % url) ], context=context) if ids: removal_blocked_by[attachment.id] = Views.read(cr, uid, ids, ['name'], context=context) else: attachments_to_remove.append(attachment.id) if attachments_to_remove: self.unlink(cr, uid, attachments_to_remove, context=context) return removal_blocked_by
def record_to_html(self, record, field_name, options, values=None): assert options['tagName'] != 'img',\ "Oddly enough, the root tag of an image field can not be img. " \ "That is because the image goes into the tag, or it gets the " \ "hose again." 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 = 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.unicodifier(img)
def record_to_html(self, cr, uid, field_name, record, column, options=None, context=None): if options is None: options = {} 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 = field_browse.name_get()[0][1] val = { "name": value.split("\n")[0], "address": 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], "website": field_browse.website, "email": field_browse.email, "fields": opf, "object": field_browse, "options": options, } 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=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 = 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 = {} 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 = field_browse.name_get()[0][1] val = { 'name': value.split("\n")[0], 'address': 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], 'website': field_browse.website, 'email': field_browse.email, 'fields': opf, 'object': field_browse, 'options': options } html = self.pool["ir.ui.view"].render(cr, uid, "base.contact", val, engine='ir.qweb', context=context).decode('utf8') return HTMLSafe(html)
def try_remove_file(self, cr, uid, ids, context=None): Views = self.pool['ir.ui.view'] attachments_to_remove = [] # views blocking removal of the attachment removal_blocked_by = {} for attachment in self.browse(cr, uid, ids, context=context): # in-document URLs are html-escaped, a straight search will not # find them url = escape(attachment.website_file_url) ids = Views.search(cr, uid, [ "|", ('arch', 'like', '"%s"' % url), ('arch', 'like', "'%s'" % url) ], context=context) if ids: removal_blocked_by[attachment.id] = Views.read(cr, uid, ids, ['name'], context=context) else: attachments_to_remove.append(attachment.id) if attachments_to_remove: self.unlink(cr, uid, attachments_to_remove, context=context) return removal_blocked_by
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, record, field_name, options, values=None): assert options['tagName'] != 'img',\ "Oddly enough, the root tag of an image field can not be img. " \ "That is because the image goes into the tag, or it gets the " \ "hose again." 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 = 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.unicodifier(img)
def try_remove(self, cr, uid, ids, context=None): """ Removes a web-based image attachment if it is used by no view (template) Returns a dict mapping attachments which would not be removed (if any) mapped to the views preventing their removal """ Views = self.pool['ir.ui.view'] attachments_to_remove = [] # views blocking removal of the attachment removal_blocked_by = {} for attachment in self.browse(cr, uid, ids, context=context): # in-document URLs are html-escaped, a straight search will not # find them url = escape(attachment.website_url) ids = Views.search(cr, uid, ["|", ('arch', 'like', '"%s"' % url), ('arch', 'like', "'%s'" % url)], context=context) if ids: removal_blocked_by[attachment.id] = Views.read( cr, uid, ids, ['name'], context=context) else: attachments_to_remove.append(attachment.id) if attachments_to_remove: self.unlink(cr, uid, attachments_to_remove, context=context) return removal_blocked_by
def to_html(self, cr, uid, field_name, record, options, source_element, t_att, g_att, qweb_context, context=None): """ Converts a ``t-field`` to its HTML output. A ``t-field`` may be extended by a ``t-field-options``, which is a JSON-serialized mapping of configuration values. A default configuration key is ``widget`` which can override the field's own ``_type``. """ try: content = self.record_to_html( cr, uid, field_name, record, record._model._all_columns[field_name].column, options, context=context) if options.get('html-escape', True): content = escape(content) elif hasattr(content, '__html__'): content = content.__html__() except Exception: _logger.warning("Could not get field %s for model %s", field_name, record._model._name, exc_info=True) content = None if context and context.get('inherit_branding'): # add branding attributes g_att += ''.join(' %s="%s"' % (name, escape(value)) for name, value in self.attributes( cr, uid, field_name, record, options, source_element, g_att, t_att, qweb_context)) return self.render_element(cr, uid, source_element, t_att, g_att, qweb_context, content)
def html_escape(string, options): """ Automatically escapes content unless options['html-escape'] is set to False :param str string: :param dict options: """ return escape(string) if not options or options.get('html-escape', True) else string
def google_map(self, *arg, **post): cr, uid, context = request.cr, request.uid, request.context partner_obj = request.registry['res.partner'] # filter real ints from query parameters and build a domain clean_ids = [] for s in post.get('partner_ids', "").split(","): try: i = int(s) clean_ids.append(i) except ValueError: pass # search for partners that can be displayed on a map domain = [("id", "in", clean_ids), ('website_published', '=', True), ('is_company', '=', True)] partners_ids = partner_obj.search(cr, SUPERUSER_ID, domain, context=context) # browse and format data partner_data = { "counter": len(partners_ids), "partners": [] } request.context.update({'show_address': True}) for partner in partner_obj.browse(cr, SUPERUSER_ID, partners_ids, context=context): # TODO in master, do not use `escape` but `t-esc` in the qweb template. partner_data["partners"].append({ 'id': partner.id, 'name': escape(partner.name), 'address': escape('\n'.join(partner.name_get()[0][1].split('\n')[1:])), 'latitude': escape(str(partner.partner_latitude)), 'longitude': escape(str(partner.partner_longitude)), }) if 'customers' in post.get('partner_url', ''): partner_url = '/customers/' else: partner_url = '/partners/' google_maps_api_key = request.env['ir.config_parameter'].sudo().get_param('google_maps_api_key') # generate the map values = { 'partner_url': partner_url, 'partner_data': json.dumps(partner_data), 'google_maps_api_key': google_maps_api_key, } return request.website.render("website_google_map.google_map", values)
def _get_website_file_count(self): count = 0 if self.website_file: url = escape(self.website_file_url) count = self.env['ir.ui.view'].search_count( ["|", ('arch', 'like', '"%s"' % url), ('arch', 'like', "'%s'" % url)]) self.website_file_count = count
def record_to_html(self, cr, uid, field_name, record, column, options=None, context=None): if options is None: options = {} 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 = field_browse.name_get()[0][1] val = { 'name': value.split("\n")[0], 'address': 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], 'website': field_browse.website, 'email': field_browse.email, 'fields': opf, 'object': field_browse, 'options': options } html = self.pool["ir.ui.view"].render(cr, uid, "base.contact", val, engine='ir.qweb', context=context).decode('utf8') return HTMLSafe(html)
def _get_website_file_count(self): count = 0 if self.website_file: url = escape(self.website_file_url) count = self.env['ir.ui.view'].search_count([ "|", ('arch', 'like', '"%s"' % url), ('arch', 'like', "'%s'" % url) ]) self.website_file_count = count
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 = {} if options.get('html-escape', True): string = escape(string) return HTMLSafe(string.replace('\n', '<br>\n'))
def event_track_proposal_post(self, event, **post): cr, uid, context = request.cr, request.uid, request.context tobj = request.registry['event.track'] tags = [] for tag in event.allowed_track_tag_ids: if post.get('tag_' + str(tag.id)): tags.append(tag.id) track_description = '''<section> <div class="container"> <div class="row"> <div class="col-md-12 text-center"> <h2>%s</h2> </div> <div class="col-md-12"> <p>%s</p> </div> <div class="col-md-12"> <h3>About The Author</h3> <p>%s</p> </div> </div> </div> </section>''' % (escape(post['track_name']), escape( post['description']), escape(post['biography'])) track_id = tobj.create(cr, openerp.SUPERUSER_ID, { 'name': post['track_name'], 'event_id': event.id, 'tag_ids': [(6, 0, tags)], 'user_id': False, 'description': track_description }, context=context) tobj.message_post( cr, openerp.SUPERUSER_ID, [track_id], body="""Proposed By: %s<br/> Mail: <a href="mailto:%s">%s</a><br/> Phone: %s""" % (escape(post['partner_name']), escape(post['email_from']), escape(post['email_from']), escape(post['phone'])), context=context) track = tobj.browse(cr, uid, track_id, context=context) values = {'track': track, 'event': event} return request.website.render( "website_event_track.event_track_proposal_success", values)
def _compute_kanban_actions(self): for record in self: result_string3 = '' for action in record.change_response_ids: bounding_length = 25 tmp_list = action.name.split() for index in range(len(tmp_list)): if len(tmp_list[index]) > bounding_length: tmp_list[index] = (tmp_list[index][:bounding_length] + '...') tmp_action_name = " ".join(tmp_list) if action.stage_id.state == 'open': tmp_string3 = escape(u': {0}'.format(tmp_action_name)) result_string3 += u'<li><b>DOING</b>{}</li>'.format( tmp_string3) elif action.stage_id.state == 'draft': tmp_string3 = escape(u': {0}'.format(tmp_action_name)) result_string3 += u'<li><b>TODO</b>{}</li>'.format( tmp_string3) elif action.stage_id.state == 'pending': tmp_string3 = escape(u': {0}'.format(tmp_action_name)) result_string3 += u'<li><b>BLOCKED</b>{}</li>'.format( tmp_string3) record.kanban_actions = '<ul>' + result_string3 + '</ul>'
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=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 event_track_proposal_post(self, event, **post): cr, uid, context = request.cr, request.uid, request.context tobj = request.registry['event.track'] tags = [] for tag in event.allowed_track_tag_ids: if post.get('tag_'+str(tag.id)): tags.append(tag.id) track_description = '''<section> <div class="container"> <div class="row"> <div class="col-md-12 text-center"> <h2>%s</h2> </div> <div class="col-md-12"> <p>%s</p> </div> <div class="col-md-12"> <h3>About The Author</h3> <p>%s</p> </div> </div> </div> </section>''' % (escape(post['track_name']), escape(post['description']), escape(post['biography'])) track_id = tobj.create(cr, openerp.SUPERUSER_ID, { 'name': post['track_name'], 'event_id': event.id, 'tag_ids': [(6, 0, tags)], 'user_id': False, 'description': track_description }, context=context) tobj.message_post(cr, openerp.SUPERUSER_ID, [track_id], body="""Proposed By: %s<br/> Mail: <a href="mailto:%s">%s</a><br/> Phone: %s""" % (escape(post['partner_name']), escape(post['email_from']), escape(post['email_from']), escape(post['phone'])), context=context) track = tobj.browse(cr, uid, track_id, context=context) values = {'track': track, 'event':event} return request.website.render("website_event_track.event_track_proposal_success", values)
def try_remove_file(self, cr, uid, ids, context=None): Views = self.pool['ir.ui.view'] attachments_to_remove = [] # views blocking removal of the attachment removal_blocked_by = {} for attachment in self.browse(cr, uid, ids, context=context): # in-document URLs are html-escaped, a straight search will not # find them url = escape(attachment.website_file_url) ids = Views.search(cr, uid, ["|", ('arch', 'like', '"%s"' % url), ('arch', 'like', "'%s'" % url)], context=context) if ids: removal_blocked_by[attachment.id] = Views.read( cr, uid, ids, ['name'], context=context) else: attachments_to_remove.append(attachment.id) if attachments_to_remove: self.unlink(cr, uid, attachments_to_remove, context=context) return removal_blocked_by
def value_to_html(self, value, options): if not value.exists(): return False opf = options and options.get('fields') or ["name", "address", "phone", "mobile", "fax", "email"] value = value.sudo().with_context(show_address=True) name_get = value.name_get()[0][1] val = { 'name': name_get.split("\n")[0], 'address': escape("\n".join(name_get.split("\n")[1:])).strip(), 'phone': value.phone, 'mobile': value.mobile, 'fax': value.fax, 'city': value.city, 'country_id': value.country_id.display_name, 'website': value.website, 'email': value.email, 'fields': opf, 'object': value, 'options': options } return self.env['ir.qweb'].render('base.contact', val)
def send_todolist_email(self, todo_name, todo_state, todo_reviewer_id, todo_user_id, ref_model=None, old_name=None): reviewer = self.env["res.users"].browse(todo_reviewer_id) user = self.env["res.users"].browse(todo_user_id) state = TODO_STATES[todo_state] if todo_state == 'done': state = '<span style="color:#080">' + state + '</span>' if todo_state == 'todo': state = '<span style="color:#A00">' + state + '</span>' if todo_state == 'cancelled': state = '<span style="color:#777">' + state + '</span>' if todo_state == 'waiting': state = '<span style="color:#b818ce">' + state + '</span>' if ref_model: subtype = 'dobtor_todolist_project_task.todolist_project_task_subtype' else: subtype = 'dobtor_todolist_core.todolist_core_subtype' body = '' partner_ids = [] if user == self.env.user and reviewer == self.env.user: body = '<p>' + '<strong>' + state + '</strong>: ' + escape( todo_name) subtype = False elif self.env.user == reviewer: body = '<p>' + escape( user.name) + ', <br><strong>' + state + '</strong>: ' + escape( todo_name) partner_ids = [user.partner_id.id] elif self.env.user == user: body = '<p>' + escape( reviewer.name ) + ', <em style="color:#999">I updated todolist item assigned to me:</em> <br><strong>' + state + '</strong>: ' + escape( todo_name) partner_ids = [reviewer.partner_id.id] else: body = '<p>' + escape(user.name) + ', ' + escape( reviewer.name ) + ', <em style="color:#999">I updated todolist item, now its assigned to ' + escape( user.name ) + ': </em> <br><strong>' + state + '</strong>: ' + escape( todo_name) partner_ids = [user.partner_id.id, reviewer.partner_id.id] if old_name: body = body + '<br><em style="color:#999">Updated from</em><br><strong>' + state + '</strong>: ' + escape( old_name) + '</p>' else: body = body + '</p>' if ref_model: for r in ref_model: if user == self.env.user and reviewer == self.env.user: subtype = False r.message_post(message_type='comment', subtype=subtype, body=body, partner_ids=partner_ids) else: self.message_post(subject='Your todo list', message_type='comment', subtype=subtype, body=body, partner_ids=partner_ids)
def apl_map(self, *arg, **post): print "Start Create maps" cr, uid, context = request.cr, request.uid, request.context pillar_obj = request.registry['uis.papl.pillar'] apl_obj=request.registry['uis.papl.apl'] trans_obj=request.registry['uis.papl.transformer'] values="" clean_ids=[] for s in post.get('apl_ids',"").split(","): try: i=int(s) clean_ids.append(i) print i except ValueError: pass domain=[("id","in",clean_ids)] apl_ids=apl_obj.search(cr, uid, domain, context=context) #apl_ids=apl_obj.search(cr, SUPERUSER_ID, domain, context=context) pillar_data={ "counter":0, "latitude":0, "longitude":0, "pillars":[] } lines_data={ "counter":0, "taps":[] } ktp_data={ "counter":0, "trans":[] } s_data={ "counter":0 } minlat=120 maxlat=0 minlong=120 maxlong=0 for apl_id in apl_obj.browse(cr, uid, apl_ids, context=context): print apl_id.name apl_id.pillar_id.sorted(key=lambda r: r.num_by_vl) for tap in apl_id.tap_ids: lines_data["counter"]=lines_data["counter"]+1 line={ "counter":0, "type":0, "coord":[] } elevation={ "counter":0, "values":[] } max_num=0 for pillar in tap.pillar_ids: if pillar.num_by_vl>max_num: max_num=pillar.num_by_vl end_pillar=pillar i=0 np=end_pillar n_id=np.id pillar_cnt=tap.pillar_cnt print tap.name+"_"+str(pillar_cnt) while (n_id>0) and (pillar_cnt-i>=0): print np.name line["counter"]=line["counter"]+1 line["coord"].append({ 'ltd':np.latitude, 'lng':np.longitude }) elevation["counter"]=elevation["counter"]+1 elevation["values"].append({ 'x':np.num_by_vl, 'elevation':np.elevation }) np=np.parent_id n_id=np.id i=i+1 print i lines_data["taps"].append({ 'id':tap.id, 'name': tap.name, 'apl':apl_id.name, 'apl_id':apl_id.name, 'line':line, 'elevation':elevation, }) for pillar_id in apl_id.pillar_id: #print "Do pillar"+pillar_id.name pillar_data["counter"]=pillar_data["counter"]+1 if pillar_id.latitude>maxlat: maxlat=pillar_id.latitude if pillar_id.latitude<minlat: minlat=pillar_id.latitude if pillar_id.longitude>maxlong: maxlong=pillar_id.longitude if pillar_id.longitude<minlong: minlong=pillar_id.longitude pillar_data["pillars"].append({ 'id':pillar_id.id, 'name':pillar_id.name, 'apl':apl_id.name, 'apl_id':apl_id.id, 'tap_id':pillar_id.tap_id.id, 'elevation':pillar_id.elevation, 'latitude': escape(str(pillar_id.latitude)), 'longitude': escape(str(pillar_id.longitude)), 'num_by_vl':pillar_id.num_by_vl, 'prev_id':pillar_id.parent_id.id, #'prevlatitude': escape(str(pillar_id.prev_latitude)), #'prevlangitude': escape(str(pillar_id.prev_longitude)) }) domain=[("apl_id","=",apl_id.id)] trans_ids=trans_obj.search(cr, uid, domain, context=context) for trans in trans_obj.browse(cr, uid, trans_ids, context=context): print trans.name ktp_data["counter"]=ktp_data["counter"]+1 ktp_data["trans"].append({ 'id':trans.id, 'name':trans.name, 'apl':trans.apl_id.name, 'apl_id':trans.apl_id.id, 'tap_id':trans.tap_id.id, 'state':trans.state, 'latitude': escape(str(trans.latitude)), 'longitude': escape(str(trans.longitude)), }) medlat=(maxlat+minlat)/2 medlong=(maxlong+minlong)/2 pillar_data["latitude"]=medlat pillar_data["longitude"]=medlong values = { #'partner_url': post.get('partner_url'), 'pillar_data': json.dumps(pillar_data), 'lines_data': json.dumps(lines_data), 'ktp_data': json.dumps(ktp_data), 'apl_ids':json.dumps(clean_ids) } return request.render("uis_ag_google_maps.uis_google_map", values)
def _get_pillar_data(self, clean_ids): cr, uid, context = request.cr, request.uid, request.context #code _get_pillar_data apl_obj = request.registry['uis.papl.apl'] pillar_data = { "counter": 0, "latitude": 0, "longitude": 0, "pillars": [] } minlat = 120 maxlat = 0 minlong = 120 maxlong = 0 domain = [("id", "in", clean_ids)] apl_ids = apl_obj.search(cr, uid, domain, context=context) for apl_id in apl_obj.browse(cr, uid, apl_ids, context=context): apl_id.pillar_id.sorted(key=lambda r: r.num_by_vl) for pillar_id in apl_id.pillar_id: #print "Do pillar"+pillar_id.name pillar_data["counter"] = pillar_data["counter"] + 1 if pillar_id.latitude > maxlat: maxlat = pillar_id.latitude if pillar_id.latitude < minlat: minlat = pillar_id.latitude if pillar_id.longitude > maxlong: maxlong = pillar_id.longitude if pillar_id.longitude < minlong: minlong = pillar_id.longitude pillar_data["pillars"].append({ 'id': pillar_id.id, 'name': pillar_id.name, 'apl': apl_id.name, 'apl_id': apl_id.id, 'tap_id': pillar_id.tap_id.id, 'elevation': pillar_id.elevation, 'latitude': escape(str(pillar_id.latitude)), 'longitude': escape(str(pillar_id.longitude)), 'num_by_vl': pillar_id.num_by_vl, 'prev_id': pillar_id.parent_id.id, 'type_id': pillar_id.pillar_type_id.id, 'rotation': 0, #Add direction pillar 'state': 'EXPLOTATION' #Add state from MRO #'prevlatitude': escape(str(pillar_id.prev_latitude)), #'prevlangitude': escape(str(pillar_id.prev_longitude)) }) medlat = (maxlat + minlat) / 2 medlong = (maxlong + minlong) / 2 pillar_data["latitude"] = medlat pillar_data["longitude"] = medlong pillar_data["minlat"] = minlat pillar_data["maxlat"] = maxlat pillar_data["minlong"] = minlong pillar_data["maxlong"] = maxlong #end code _pillar_data return pillar_data
def _build_attribute(name, value): value = escape(value) if isinstance(name, unicode): name = name.encode('utf-8') if isinstance(value, unicode): value = value.encode('utf-8') return ' %s="%s"' % (name, value)
def _compile_directive_snippet(self, el, options): el.set('t-call', el.attrib.pop('t-snippet')) name = self.env['ir.ui.view'].search([('key', '=', el.attrib.get('t-call'))]).display_name thumbnail = el.attrib.pop('t-thumbnail', "oe-thumbnail") div = u'<div name="%s" data-oe-type="snippet" data-oe-thumbnail="%s">' % (escape(ir_qweb.unicodifier(name)), escape(ir_qweb.unicodifier(thumbnail))) return [self._append(ast.Str(div))] + self._compile_node(el, options) + [self._append(ast.Str(u'</div>'))]
def format(self, inner, options, qwebcontext): return escape(self._format(inner, options, qwebcontext))
def apl_map(self, *arg, **post): print "Start Create maps" cr, uid, context = request.cr, request.uid, request.context pillar_obj = request.registry['uis.papl.pillar'] apl_obj = request.registry['uis.papl.apl'] values = "" clean_ids = [] for s in post.get('apl_ids', "").split(","): try: i = int(s) clean_ids.append(i) print i except ValueError: pass domain = [("id", "in", clean_ids)] apl_ids = apl_obj.search(cr, uid, domain, context=context) #apl_ids=apl_obj.search(cr, SUPERUSER_ID, domain, context=context) pillar_data = { "counter": 0, "latitude": 0, "longitude": 0, "pillars": [] } s_data = {"counter": 0} minlat = 120 maxlat = 0 minlong = 120 maxlong = 0 for apl_id in apl_obj.browse(cr, uid, apl_ids, context=context): print apl_id.name apl_id.pillar_id.sorted(key=lambda r: r.num_by_vl) print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" for pillar_id in apl_id.pillar_id: print "Do pillar" + pillar_id.name pillar_data["counter"] = pillar_data["counter"] + 1 if pillar_id.latitude > maxlat: maxlat = pillar_id.latitude if pillar_id.latitude < minlat: minlat = pillar_id.latitude if pillar_id.longitude > maxlong: maxlong = pillar_id.longitude if pillar_id.longitude < minlong: minlong = pillar_id.longitude pillar_data["pillars"].append({ 'id': pillar_id.id, 'name': pillar_id.name, 'apl': apl_id.name, 'latitude': escape(str(pillar_id.latitude)), 'longitude': escape(str(pillar_id.longitude)), #'prevlatitude': escape(str(pillar_id.prev_latitude)), #'prevlangitude': escape(str(pillar_id.prev_longitude)) }) medlat = (maxlat + minlat) / 2 medlong = (maxlong + minlong) / 2 pillar_data["latitude"] = medlat pillar_data["longitude"] = medlong values = { #'partner_url': post.get('partner_url'), 'pillar_data': json.dumps(pillar_data) } return request.render("uis_ag_google_maps.uis_google_map", values)
def apl_map(self, *arg, **post): print "Start Create maps" cr, uid, context = request.cr, request.uid, request.context pillar_obj = request.registry['uis.papl.pillar'] apl_obj=request.registry['uis.papl.apl'] values="" clean_ids=[] for s in post.get('apl_ids',"").split(","): try: i=int(s) clean_ids.append(i) print i except ValueError: pass domain=[("id","in",clean_ids)] apl_ids=apl_obj.search(cr, uid, domain, context=context) #apl_ids=apl_obj.search(cr, SUPERUSER_ID, domain, context=context) pillar_data={ "counter":0, "latitude":0, "longitude":0, "pillars":[] } s_data={ "counter":0 } minlat=120 maxlat=0 minlong=120 maxlong=0 for apl_id in apl_obj.browse(cr, uid, apl_ids, context=context): print apl_id.name apl_id.pillar_id.sorted(key=lambda r: r.num_by_vl) print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" for pillar_id in apl_id.pillar_id: print "Do pillar"+pillar_id.name pillar_data["counter"]=pillar_data["counter"]+1 if pillar_id.latitude>maxlat: maxlat=pillar_id.latitude if pillar_id.latitude<minlat: minlat=pillar_id.latitude if pillar_id.longitude>maxlong: maxlong=pillar_id.longitude if pillar_id.longitude<minlong: minlong=pillar_id.longitude pillar_data["pillars"].append({ 'id':pillar_id.id, 'name':pillar_id.name, 'apl':apl_id.name, 'latitude': escape(str(pillar_id.latitude)), 'longitude': escape(str(pillar_id.longitude)), #'prevlatitude': escape(str(pillar_id.prev_latitude)), #'prevlangitude': escape(str(pillar_id.prev_longitude)) }) medlat=(maxlat+minlat)/2 medlong=(maxlong+minlong)/2 pillar_data["latitude"]=medlat pillar_data["longitude"]=medlong values = { #'partner_url': post.get('partner_url'), 'pillar_data': json.dumps(pillar_data) } return request.render("uis_ag_google_maps.uis_google_map", values)