Skip to content

Commit

Permalink
Pass filterset into render_filter_badges explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
trickeydan committed Apr 9, 2024
1 parent a0f5e1d commit 3f454f1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
22 changes: 14 additions & 8 deletions helpdesk/helpdesk/templatetags/filter_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from django import template
from django.forms import Field
from django_filters.fields import ChoiceField

if TYPE_CHECKING:
from django_filters import FilterSet

register = template.Library()


Expand All @@ -19,17 +24,18 @@ def _get_value_display_for_field(field: Field, value: Any) -> Any:
return value


@register.inclusion_tag("inc/tags/filter_badges.html", takes_context=True)
def render_filter_badges(context: dict[str, Any]) -> dict[str, Any]:
fltr = context["filter"]

if fltr.is_valid():
cleaned_data = {k: v for k, v in fltr.form.cleaned_data.items() if v is not None and v != ""}
@register.inclusion_tag("inc/tags/filter_badges.html")
def render_filter_badges(filterset: FilterSet) -> dict[str, Any]:
if filterset.is_valid(): # type: ignore[no-untyped-call]
cleaned_data = {k: v for k, v in filterset.form.cleaned_data.items() if v is not None and v != ""}
else:
cleaned_data = {}

filter_badges = {
(fltr.form.fields[field_name].label, _get_value_display_for_field(fltr.form.fields[field_name], value))
(
filterset.form.fields[field_name].label,
_get_value_display_for_field(filterset.form.fields[field_name], value),
)
for field_name, value in cleaned_data.items()
}

Expand Down
2 changes: 1 addition & 1 deletion helpdesk/templates/inc/tags/filter_badges.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
</div>
{% endfor %}
</div>
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion helpdesk/templates/teams/team_detail_tickets.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% block content %}
{% include "inc/nav/team-tabs.html" with active="tickets" team=object %}
<div class="container">
{% render_filter_badges %}
{% render_filter_badges filter %}
<div class="columns">
<div class="column">
{% render_table table %}
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/templates/teams/team_filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

{% block content %}
<div class="container">
{% render_filter_badges %}
{% render_filter_badges filter %}
<div class="columns">
<div class="column">
{% render_table table %}
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/templates/tickets/ticketqueue_assigned.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{% block content %}
<div class="container">
{% render_filter_badges %}
{% render_filter_badges filter %}
<div class="columns">
{% render_table table %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/templates/tickets/ticketqueue_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</aside>
</div>
<div class="column">
{% render_filter_badges %}
{% render_filter_badges filter %}
<p class="block">{{ object.description }}</p>
{% render_table table %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/templates/tickets/tickets_all.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

{% block content %}
<div class="container">
{% render_filter_badges %}
{% render_filter_badges filter %}
<div class="columns">
{% render_table table %}
</div>
Expand Down

0 comments on commit 3f454f1

Please sign in to comment.