diff --git a/tom_common/templates/tom_common/partials/profile_app_addons.html b/tom_common/templates/tom_common/partials/profile_app_addons.html index 910e1284..a7335824 100644 --- a/tom_common/templates/tom_common/partials/profile_app_addons.html +++ b/tom_common/templates/tom_common/partials/profile_app_addons.html @@ -1,19 +1,20 @@ -{% load user_extras %} +{% load user_extras tom_common_extras %} {% load bootstrap4 %}
-
+
{% for profile in profile_list %} -
- {% include profile %} -
- {% if forloop.counter|divisibleby:2 %} + + {% if forloop.counter > profile_list|length|add:"1"|multiplyby:"0.5" and forloop.counter <= profile_list|length|add:"1"|multiplyby:"0.5"|add:"1" %}
-
+ +
{% endif %} + {% include profile %} {% empty %} This user has no profile. {% endfor %} +
\ No newline at end of file diff --git a/tom_common/templatetags/tom_common_extras.py b/tom_common/templatetags/tom_common_extras.py index 500b6029..4b07ae87 100644 --- a/tom_common/templatetags/tom_common_extras.py +++ b/tom_common/templatetags/tom_common_extras.py @@ -108,6 +108,15 @@ def truncate_number(value): return value +@register.filter +def multiplyby(value, arg): + """ + Multiply the value by a number and return a float. + `{% value|multiplyby:"x.y" %}` + """ + return float(value) * float(arg) + + @register.filter def addstr(arg1, arg2): """ diff --git a/tom_common/templatetags/user_extras.py b/tom_common/templatetags/user_extras.py index db0b1e3c..1e375b7d 100644 --- a/tom_common/templatetags/user_extras.py +++ b/tom_common/templatetags/user_extras.py @@ -61,21 +61,22 @@ def profile_app_addons(context, user): for app in apps.get_app_configs(): try: profile_details = app.profile_details() - if profile_details: - for profile in profile_details: - try: - clazz = import_string(profile['context']) - except ImportError: - logger.warning(f'WARNING: Could not import context for {app.name} profile from ' - f'{profile["context"]}.\n' - f'Are you sure you have the right path?') - continue - new_context = clazz(user) - for item in new_context: - context[item] = new_context[item] - partial_list.append(profile['partial']) except AttributeError: - pass + continue + if profile_details: + for profile in profile_details: + try: + clazz = import_string(profile['context']) + except ImportError: + logger.warning(f'WARNING: Could not import context for {app.name} profile from ' + f'{profile["context"]}.\n' + f'Are you sure you have the right path?') + continue + new_context = clazz(user) + for item in new_context: + context[item] = new_context[item] + partial_list.append(profile['partial']) + context['user'] = user context['profile_list'] = partial_list return context