forked from openlabs/poweremail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poweremail_engines.py
84 lines (78 loc) · 3.07 KB
/
poweremail_engines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# To change this template, choose Tools | Templates
# and open the template in the editor.
from osv import fields,osv
import pooler
import netsvc
import re
class poweremail_engines(osv.osv):
_name = "poweremail.engines"
_description = "Power Email Engine"
# def __init__(self):
# print "Started Engine"
def check(self):
print "Start self check"
def strip_html(self,text):
#Removes HTML, Have to check if still relevent
if text:
def fixup(m):
text = m.group(0)
if text[:1] == "<":
return "" # ignore tags
if text[:2] == "&#":
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
elif text[:1] == "&":
import htmlentitydefs
entity = htmlentitydefs.entitydefs.get(text[1:-1])
if entity:
if entity[:2] == "&#":
try:
return unichr(int(entity[2:-1]))
except ValueError:
pass
else:
return unicode(entity, "iso-8859-1")
return text # leave as is
return re.sub("(?s)<[^>]*>|&#?\w+;", fixup, text)
def parsevalue(self,cr,uid,id,message,templateid,context):
#id: ID of the template's model's record to be used
#message: the complete text including placeholders
#templateid: the template id of the template
#context: TODO
#print cr,uid,id,message,templateid,context
if message:
logger = netsvc.Logger()
def merge(match):
template = self.pool.get("poweremail.templates").browse(cr,uid,templateid,context)
obj_pool = self.pool.get(template.object_name.model)
obj = obj_pool.browse(cr, uid, id, context)
exp = str(match.group()[2:-2]).strip()
#print "level 1:",exp
exp_spl = exp.split('/')
#print "level 2:",exp_spl
try:
result = eval(exp_spl[0], {'object':obj,})
except:
result = "Rendering Error"
#print "result:",result
try:
if result in (None, False):
if len(exp_spl)>1:
return exp_spl[1]
else:
return 'Not Available'
return str(result)
except:
return "Rendering Error"
if message:
com = re.compile('(\[\[.+?\]\])')
retmessage = com.sub(merge, message)
else:
retmessage=""
return retmessage
poweremail_engines()