Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1231] Fix breadcrumbs in plans #552

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/open_inwoner/accounts/tests/test_action_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def test_action_history(self):
self.assertEqual(response.status_code, 200)
self.assertContains(response, self.action.name)

def test_action_history_breadcrumbs(self):
response = self.app.get(self.history_url, user=self.user)
crumbs = response.pyquery(".breadcrumbs__list-item")
self.assertIn(_("Mijn profiel"), crumbs[1].text_content())
self.assertIn(_("Mijn acties"), crumbs[2].text_content())

def test_action_history_not_your_action(self):
other_user = UserFactory()
self.app.get(self.history_url, user=other_user, status=404)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
{% button icon="edit" text=_("Bewerken") href=action_url icon_outlined=True transparent=True %}
</div>
<div class="dropdown__item">
{% button icon="history" text=_("History") href="accounts:action_history" uuid=action.uuid icon_outlined=True transparent=True %}
{% if plan %}
{% url 'plans:plan_action_history' plan_uuid=plan.uuid uuid=action.uuid as action_history_url %}
{% button icon="history" text=_("History") href=action_history_url uuid=action.uuid icon_outlined=True transparent=True %}
{% else %}
{% button icon="history" text=_("History") href="accounts:action_history" uuid=action.uuid icon_outlined=True transparent=True %}
{% endif %}
</div>
<div class="dropdown__item">
{% get_action_delete_url action=action plan=plan as action_url %}
Expand Down
11 changes: 11 additions & 0 deletions src/open_inwoner/plans/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def setUp(self) -> None:
"plans:plan_action_edit",
kwargs={"plan_uuid": self.plan.uuid, "uuid": self.action.uuid},
)
self.action_history_url = reverse(
"plans:plan_action_history",
kwargs={"plan_uuid": self.plan.uuid, "uuid": self.action.uuid},
)
self.action_edit_status_url = reverse(
"plans:plan_action_edit_status",
kwargs={"plan_uuid": self.plan.uuid, "uuid": self.action.uuid},
Expand Down Expand Up @@ -484,6 +488,13 @@ def test_plan_action_edit_not_changed(self):
# no notification is sent
self.assertEqual(len(mail.outbox), 0)

def test_plan_actions_history_breadcrumbs(self):
response = self.app.get(self.action_history_url, user=self.user)
crumbs = response.pyquery(".breadcrumbs__list-item")
self.assertIn(_("Samenwerking"), crumbs[1].text_content())
self.assertIn(self.plan.title, crumbs[2].text_content())
self.assertIn(self.action.name, crumbs[3].text_content())

def test_plan_action_delete_login_required_http_403(self):
response = self.client.post(self.action_delete_url)
self.assertEquals(response.status_code, 403)
Expand Down
6 changes: 6 additions & 0 deletions src/open_inwoner/plans/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
PlanActionDeleteView,
PlanActionEditStatusTagView,
PlanActionEditView,
PlanActionHistoryView,
PlanCreateView,
PlanDetailView,
PlanEditView,
Expand Down Expand Up @@ -42,5 +43,10 @@
PlanActionDeleteView.as_view(),
name="plan_action_delete",
),
path(
"<uuid:plan_uuid>/actions/<str:uuid>/history/",
PlanActionHistoryView.as_view(),
name="plan_action_history",
),
path("<uuid:uuid>/export/", PlanExportView.as_view(), name="plan_export"),
]
31 changes: 28 additions & 3 deletions src/open_inwoner/plans/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from open_inwoner.accounts.views.actions import (
ActionCreateView,
ActionDeleteView,
ActionHistoryView,
ActionUpdateStatusTagView,
ActionUpdateView,
BaseActionFilter,
Expand Down Expand Up @@ -178,7 +179,7 @@ class PlanDetailView(
@cached_property
def crumbs(self):
return [
(_("Samenwerkingsplannen"), reverse("plans:plan_list")),
(_("Samenwerken"), reverse("plans:plan_list")),
(self.get_object().title, reverse("plans:plan_detail", kwargs=self.kwargs)),
]

Expand Down Expand Up @@ -223,8 +224,8 @@ class PlanCreateView(
@cached_property
def crumbs(self):
return [
(_("Samenwerkingsplannen"), reverse("plans:plan_list")),
(_("Maak samenwerkingsplan aan"), reverse("plans:plan_create")),
(_("Samenwerken"), reverse("plans:plan_list")),
(_("Start nieuwe samenwerking"), reverse("plans:plan_create")),
]

def get_form_kwargs(self):
Expand Down Expand Up @@ -520,6 +521,30 @@ def on_delete_action(self, action):
)


class PlanActionHistoryView(ActionHistoryView):
@cached_property
def crumbs(self):
return [
(_("Samenwerking"), reverse("plans:plan_list")),
(
self.get_plan().title,
reverse("plans:plan_detail", kwargs={"uuid": self.get_plan().uuid}),
),
(
_("History of {}").format(self.object.name),
reverse("plans:plan_action_history", kwargs=self.kwargs),
),
]

def get_plan(self):
try:
return Plan.objects.connected(self.request.user).get(
uuid=self.kwargs.get("plan_uuid")
)
except ObjectDoesNotExist as e:
raise Http404


class PlanExportView(
PlansEnabledMixin, LogMixin, LoginRequiredMixin, ExportMixin, DetailView
):
Expand Down