2022-05-16 20:20:36 +00:00
|
|
|
# Functions not dependent on advlabdb
|
|
|
|
|
|
|
|
from flask import flash
|
2022-06-01 21:03:13 +00:00
|
|
|
from markupsafe import Markup
|
2022-05-16 20:20:36 +00:00
|
|
|
|
|
|
|
|
2022-06-28 15:01:42 +00:00
|
|
|
def flashRandomPassword(email: str, password: str):
|
|
|
|
flash(f"New random password for email {email}: {password}", category="warning")
|
2022-05-16 20:20:36 +00:00
|
|
|
|
2022-04-18 16:04:17 +00:00
|
|
|
|
|
|
|
def parse_bool(str):
|
|
|
|
str_lower = str.lower()
|
|
|
|
if str_lower == "false":
|
|
|
|
return False
|
|
|
|
elif str_lower == "true":
|
|
|
|
return True
|
|
|
|
else:
|
2022-05-09 00:10:30 +00:00
|
|
|
raise ValueError(f'Can not parse a bool from "{str}"')
|
2022-06-01 21:03:13 +00:00
|
|
|
|
|
|
|
|
2022-06-01 21:56:55 +00:00
|
|
|
def deep_getattr(object, composed_name):
|
|
|
|
names = composed_name.split(".")
|
|
|
|
attr = getattr(object, names[0])
|
|
|
|
for name in names[1:]:
|
|
|
|
attr = getattr(attr, name)
|
|
|
|
|
|
|
|
return attr
|
|
|
|
|
|
|
|
|
2022-06-01 21:03:13 +00:00
|
|
|
def missing_formatter(view, context, model, name):
|
2022-06-01 21:56:55 +00:00
|
|
|
attr = deep_getattr(model, name)
|
2022-06-01 21:03:13 +00:00
|
|
|
if attr is None:
|
2022-06-28 01:53:17 +00:00
|
|
|
return Markup("<span style='color: red;'>MISSING</span>")
|
2022-06-01 21:03:13 +00:00
|
|
|
|
|
|
|
return attr
|
2022-06-01 21:15:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def str_without_semester_formatter(view, context, model, name):
|
2022-06-01 21:56:55 +00:00
|
|
|
attr = deep_getattr(model, name)
|
2022-06-01 21:15:33 +00:00
|
|
|
if attr is not None:
|
|
|
|
return attr.str_without_semester()
|
|
|
|
|
|
|
|
return attr
|
2022-06-01 21:56:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def str_formatter(view, context, model, name):
|
|
|
|
attr = deep_getattr(model, name)
|
|
|
|
if attr is not None:
|
|
|
|
return attr.str()
|
|
|
|
|
|
|
|
return attr
|