From dfb3bed757ab4e1795750cfa64c8786932be9959 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Tue, 22 Jan 2019 17:39:11 +0000 Subject: [PATCH] make it easier to control the logic around what is shown to the users --- .../templates/funds/includes/status_bar.html | 20 +++---------------- .../funds/templatetags/statusbar_tags.py | 20 +++++++++++++++++++ opentech/apply/funds/workflow.py | 5 ++--- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/opentech/apply/funds/templates/funds/includes/status_bar.html b/opentech/apply/funds/templates/funds/includes/status_bar.html index 042260bda..eb5235a2e 100644 --- a/opentech/apply/funds/templates/funds/includes/status_bar.html +++ b/opentech/apply/funds/templates/funds/includes/status_bar.html @@ -1,3 +1,4 @@ +{% load statusbar_tags %} <div class="status-bar {{ class }}"> {% for phase in phases %} {% ifchanged phase.step %} @@ -8,23 +9,8 @@ status-bar__item--is-complete {% endif %}"> <span class="status-bar__tooltip" - {% if phase.step != current_phase.step %} - {% if phase.step > current_phase.step %} - data-title="{{ phase.future_name }}" aria-label="{{ current_phase.future_name }}" - {% else %} - {% if public %} - data-title="{{ phase.public_name }}" aria-label="{{ phase.public_name }}" - {% else %} - data-title="{{ phase }}" aria-label="{{ phase }}" - {% endif %} - {% endif %} - {% else %} - {% if public %} - data-title="{{ current_phase.public_name }}" aria-label="{{ current_phase.public_name }}" - {% else %} - data-title="{{ current_phase }}" aria-label="{{ current_phase }}" - {% endif %} - {% endif %} + {% status_display current_phase phase public as display_text %} + data-title="{{ display_text }}" aria-label="{{ display_text }}" ></span> <svg class="status-bar__icon"><use xlink:href="#tick-alt"></use></svg> </div> diff --git a/opentech/apply/funds/templatetags/statusbar_tags.py b/opentech/apply/funds/templatetags/statusbar_tags.py index ae889c972..438adb218 100644 --- a/opentech/apply/funds/templatetags/statusbar_tags.py +++ b/opentech/apply/funds/templatetags/statusbar_tags.py @@ -34,3 +34,23 @@ def status_bar(workflow, current_phase, user, css_class='', same_stage=False): 'class': css_class, 'public': user.is_applicant, } + + +@register.simple_tag() +def status_display(current_phase, phase, public): + if phase.step == current_phase.step: + if public: + return current_phase.public_name + else: + return current_phase.display_name + + if phase.step > current_phase.step: + if public: + return phase.future_name_public + else: + return phase.future_name_staff + + if public: + return phase.public_name + else: + return phase.display_name diff --git a/opentech/apply/funds/workflow.py b/opentech/apply/funds/workflow.py index 8f0dea4cb..619f22a85 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -73,12 +73,11 @@ class Phase: self.name = name self.display_name = display if public and future: - # This prevent having to check that the display name fallback is ok for the - # public to see raise ValueError("Cant provide both a future and a public name") self.public_name = public or self.display_name - self.future_name = future or self.display_name + self.future_name_staff = future or self.display_name + self.future_name_public = future or self.public_name self.stage = stage self.permissions = Permissions(permissions) self.step = step -- GitLab