Only {{ not {{ etc

This commit is contained in:
dgtlmoon
2022-12-04 14:13:35 +01:00
parent e97c2b3224
commit dbfcc3a5a3
2 changed files with 9 additions and 13 deletions

View File

@@ -206,12 +206,6 @@ class ValidateJinja2Template(object):
from jinja2 import Environment, BaseLoader, TemplateSyntaxError
from jinja2.meta import find_undeclared_variables
regex = re.compile('{{(.*?)}}')
valid_tokens = list(notification.valid_tokens.keys())
for p in re.findall(regex, field.data):
if not p.strip() in valid_tokens:
message = field.gettext('Token \'%s\' is not a valid token or is unknown')
raise ValidationError(message % (p))
try:
jinja2_env = Environment(loader=BaseLoader)

View File

@@ -624,23 +624,25 @@ class ChangeDetectionStore:
return
# Convert old static notification tokens to jinja2 tokens
def update_11(self):
def update_10(self):
# Each watch
import re
# only { } not {{ or }}
r = r'(?<!{){(?!{)(\w+)(?<!})}(?!})'
for uuid, watch in self.data['watching'].items():
try:
n_body = watch.get('notification_body', '')
if n_body:
watch['notification_body'] = re.sub(r'{(\w+)}{1}', '{{\g<1>}}', n_body)
watch['notification_body'] = re.sub(r, '{{\g<1>}}', n_body)
n_title = watch.get('notification_title')
if n_title:
self.data['settings']['application']['notification_title'] = re.sub(r'{(\w+)}{1}', '{{\g<1>}}', n_title)
self.data['settings']['application']['notification_title'] = re.sub(r, '{{\g<1>}}', n_title)
n_urls = watch.get('notification_urls')
if n_urls:
for i, url in enumerate(n_urls):
watch['notification_urls'][i] = re.sub(r'{(\w+)}{1}', '{{\g<1>}}', url)
watch['notification_urls'][i] = re.sub(r, '{{\g<1>}}', url)
except:
continue
@@ -648,15 +650,15 @@ class ChangeDetectionStore:
# System wide
n_body = self.data['settings']['application'].get('notification_body')
if n_body:
self.data['settings']['application']['notification_body'] = re.sub(r'{(\w+)}{1}', '{{\g<1>}}', n_body)
self.data['settings']['application']['notification_body'] = re.sub(r, '{{\g<1>}}', n_body)
n_title = self.data['settings']['application'].get('notification_title')
if n_body:
self.data['settings']['application']['notification_title'] = re.sub(r'{(\w+)}{1}', '{{\g<1>}}', n_title)
self.data['settings']['application']['notification_title'] = re.sub(r, '{{\g<1>}}', n_title)
n_urls = self.data['settings']['application'].get('notification_urls')
if n_urls:
for i, url in enumerate(n_urls):
self.data['settings']['application']['notification_urls'][i] = re.sub(r'{(\w+)}{1}', '{{\g<1>}}', url)
self.data['settings']['application']['notification_urls'][i] = re.sub(r, '{{\g<1>}}', url)
return