Skip to content
Snippets Groups Projects
Commit c7ee9e306253 authored by Axel Prel's avatar Axel Prel
Browse files

make ruff happier

parent b9af52c79fd6
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,7 @@
(CONSTANT, "Constant value"),
]
DYNAMIC_PLACEHOLDER_ALLOWED_CONVERTERS = (
FIELD,
MAIL_TEMPLATE,
......@@ -142,6 +143,38 @@
]
)
def _build_field(self, sub):
if "." in sub.value:
path, name = sub.value.rsplit(".", 1)
else:
path, name = None, sub.value
conv = converter.Field(name)
if path:
conv = converter.relation(path.replace(".", "/"), conv)
return conv
def _build_image(self, sub):
if "." in sub.value:
path, name = sub.value.rsplit(".", 1)
else:
path, name = None, sub.value
conv = converter.ImageFile(name)
if path:
conv = converter.relation(path.replace(".", "/"), conv)
return conv
def _build_rel_2_many(self, sub):
# Unpack the result of finding a field with its sort order into
# variable names.
value, sorted = parse_sorted_field(sub.value)
conv = converter.RelationToMany(
value,
None,
sortkey=sortkey(sorted) if sorted else None,
converter=sub.get_children().build_converter(),
)
return conv
def build_converter(self):
d = {}
for sub in self:
......@@ -152,11 +185,5 @@
elif sub.converter == CONSTANT:
conv = converter.Constant(sub.value)
elif sub.converter == FIELD:
if "." in sub.value:
path, name = sub.value.rsplit(".", 1)
else:
path, name = None, sub.value
conv = converter.Field(name)
if path:
conv = converter.relation(path.replace(".", "/"), conv)
conv = self._build_field(sub)
elif sub.converter == IMAGE_FILE:
......@@ -162,11 +189,5 @@
elif sub.converter == IMAGE_FILE:
if "." in sub.value:
path, name = sub.value.rsplit(".", 1)
else:
path, name = None, sub.value
conv = converter.ImageFile(name)
if path:
conv = converter.relation(path.replace(".", "/"), conv)
conv = self._build_image(sub)
elif sub.converter == IMAGE_DATAURL:
conv = converter.ImageDataURL(sub.value)
elif sub.converter == QR_CODE_FILE:
......@@ -174,15 +195,7 @@
elif sub.converter == QR_CODE_DATAURL:
conv = converter.QRCodeDataURL(sub.value)
elif sub.converter == RELATION_2MANY:
# Unpack the result of finding a field with its sort order into
# variable names.
value, sorted = parse_sorted_field(sub.value)
conv = converter.RelationToMany(
value,
None,
sortkey=sortkey(sorted) if sorted else None,
converter=sub.get_children().build_converter(),
)
conv = self._build_rel_2_many(sub)
elif sub.converter == RELATION_PATH:
conv = converter.relation(
sub.value, sub.get_children().build_converter()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment