From ba07f9685af9eeeed912cae73c8554cd58aaf534 Mon Sep 17 00:00:00 2001 From: Jared Kerim Date: Wed, 30 May 2018 13:52:21 -0400 Subject: [PATCH] Show project and owner in list page title fixes #413 --- app/experimenter/experiments/tests/test_views.py | 14 ++++++++++++++ app/experimenter/experiments/views.py | 12 ++++++++++++ app/experimenter/templates/experiments/list.html | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/app/experimenter/experiments/tests/test_views.py b/app/experimenter/experiments/tests/test_views.py index f61ace533d..99a60b3889 100644 --- a/app/experimenter/experiments/tests/test_views.py +++ b/app/experimenter/experiments/tests/test_views.py @@ -14,12 +14,26 @@ from experimenter.experiments.views import ( ExperimentCreateView, ExperimentFilterset, + ExperimentFiltersetForm, ExperimentFormMixin, ExperimentOrderingForm, ) from experimenter.projects.tests.factories import ProjectFactory +class TestExperimentFiltersetForm(TestCase): + + def test_get_project_display_value_returns_project_str(self): + project = ProjectFactory.create() + form = ExperimentFiltersetForm({"project": project.id}) + self.assertEqual(form.get_project_display_value(), str(project)) + + def test_get_owner_display_value_returns_user_str(self): + user = UserFactory.create() + form = ExperimentFiltersetForm({"owner": user.id}) + self.assertEqual(form.get_owner_display_value(), str(user)) + + class TestExperimentFilterset(TestCase): def test_filters_out_archived_by_default(self): diff --git a/app/experimenter/experiments/views.py b/app/experimenter/experiments/views.py index 69109a4083..4c6908e6c4 100644 --- a/app/experimenter/experiments/views.py +++ b/app/experimenter/experiments/views.py @@ -34,6 +34,18 @@ def clean_archived(self): return False + def get_project_display_value(self): + project_id = self.data.get("project", None) + + if project_id is not None: + return str(Project.objects.get(id=project_id)) + + def get_owner_display_value(self): + user_id = self.data.get("owner", None) + + if user_id is not None: + return str(get_user_model().objects.get(id=user_id)) + class ExperimentFilterset(filters.FilterSet): archived = filters.BooleanFilter( diff --git a/app/experimenter/templates/experiments/list.html b/app/experimenter/templates/experiments/list.html index db26390364..7b4fcde2fe 100644 --- a/app/experimenter/templates/experiments/list.html +++ b/app/experimenter/templates/experiments/list.html @@ -10,6 +10,10 @@ {{ filter.form.status.value }} {% endif %} + {% if filter.form.project.value %} + {{ filter.form.get_project_display_value }} + {% endif %} + {% if filter.form.firefox_channel.value %} {{ filter.form.firefox_channel.value }} {% endif %} @@ -19,6 +23,10 @@ {{ filter.form.firefox_version.value }} {% endif %} Experiment{{ experiments|pluralize:"s" }} + + {% if filter.form.owner.value %} + by {{ filter.form.get_owner_display_value }} + {% endif %}