improve tools for protocol handling

This commit is contained in:
2021-04-28 01:38:36 +02:00
parent 6f5325678f
commit 04a426a1f9
3 changed files with 20 additions and 6 deletions

View File

@@ -59,6 +59,9 @@ class Top:
else:
raise ValueError("One of title or message is needed")
if self.body is None:
self.body = ""
def __repr__(self):
return "<TOP "+self.title+">"
@@ -92,12 +95,18 @@ def weekday(indate):
return WEEKDAYS[indate.weekday()]
def prototop(top):
result = ""
if "protostub" in dir(top) and top.protostub:
return j2env.from_string(top.protostub).render(context, top=top)
result = j2env.from_string(top.protostub).render(context, top=top)
elif top.body:
return j2env.from_string(top.body).render(context)
else:
return None
result = j2env.from_string(top.body).render(context)
for search,replace in config["protoreplace"].items():
result = result.replace(search, replace)
return result
def conf2top(top):
sender = None