1 # To change this template, choose Tools | Templates
2 # and open the template in the editor.
3 from osv import fields,osv
8 class email_template_engines(osv.osv):
9 _name = "email_template.engines"
10 _description = "Email Template Engine"
13 # print "Started Engine"
16 print "Start self check"
18 def strip_html(self,text):
19 #Removes HTML, Have to check if still relevent
24 return "" # ignore tags
28 return unichr(int(text[3:-1], 16))
30 return unichr(int(text[2:-1]))
35 entity = htmlentitydefs.entitydefs.get(text[1:-1])
37 if entity[:2] == "&#":
39 return unichr(int(entity[2:-1]))
43 return unicode(entity, "iso-8859-1")
44 return text # leave as is
45 return re.sub("(?s)<[^>]*>|&#?\w+;", fixup, text)
47 def parsevalue(self,cr,uid,id,message,templateid,context):
48 #id: ID of the template's model's record to be used
49 #message: the complete text including placeholders
50 #templateid: the template id of the template
52 #print cr,uid,id,message,templateid,context
54 logger = netsvc.Logger()
56 template = self.pool.get("email.template").browse(cr,uid,templateid,context)
57 obj_pool = self.pool.get(template.object_name.model)
58 obj = obj_pool.browse(cr, uid, id, context)
59 exp = str(match.group()[2:-2]).strip()
61 exp_spl = exp.split('/')
62 #print "level 2:",exp_spl
64 result = eval(exp_spl[0], {'object':obj,})
66 result = "Rendering Error"
67 #print "result:",result
69 if result in (None, False):
73 return 'Not Available'
76 return "Rendering Error"
78 com = re.compile('(\[\[.+?\]\])')
79 retmessage = com.sub(merge, message)
84 email_template_engines()