From 966d51f94cce8a21d3c56a787d0922c18582ff04 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Fri, 1 Jul 2022 18:49:29 +0200 Subject: [PATCH] Deal with lists in str_formatters --- advlabdb/advlabdb_independent_funs.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/advlabdb/advlabdb_independent_funs.py b/advlabdb/advlabdb_independent_funs.py index 668c61b..83d0ddb 100644 --- a/advlabdb/advlabdb_independent_funs.py +++ b/advlabdb/advlabdb_independent_funs.py @@ -37,18 +37,28 @@ def missing_formatter(view, context, model, name): def str_without_semester_formatter(view, context, model, name): attr = deep_getattr(model, name) - if attr is not None: - return attr.str_without_semester() - return attr + if attr is None: + return "" + + if hasattr(attr, "__iter__") and not isinstance(attr, str): + # List of attributes + return ", ".join([a.str_without_semester() for a in attr]) + + return attr.str_without_semester() def str_formatter(view, context, model, name): attr = deep_getattr(model, name) - if attr is not None: - return attr.str() - return attr + if attr is None: + return "" + + if hasattr(attr, "__iter__") and not isinstance(attr, str): + # List of attributes + return ", ".join([a.str() for a in attr]) + + return attr.str() def _details_link(url, attr, attr_formatter):