Skip to content

Commit

Permalink
Add team people directory filter
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb committed Nov 26, 2024
1 parent b5c7a15 commit 85bf8f8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/core/templatetags/workspace_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def build_team_breadcrumbs(request, team: Team) -> list[tuple[str, str]]:
(reverse("team-view", args=[parent_team.slug]), parent_team.short_name)
for parent_team in parent_teams
]

breadcrumbs += [(reverse("team-view", args=[team.slug]), team.short_name)]

return breadcrumbs
Expand All @@ -43,17 +42,18 @@ def breadcrumbs(context) -> list[tuple[str, str]]:
(ancestor.get_url(request), ancestor.title) for ancestor in ancestors
]
return {"breadcrumbs": breadcrumbs + extra_breadcrumbs}

has_team_breadcrumbs = context.get("team_breadcrumbs", False)
has_profile_breadcrumbs = context.get("profile_breadcrumbs", False)

# Build team breadcrumbs
if has_team_breadcrumbs or has_profile_breadcrumbs:
if has_team_breadcrumbs:
team: Team = context["team"]
return {
"breadcrumbs": build_team_breadcrumbs(request, team) + extra_breadcrumbs
}
team: Team | None = context.get("team", None)
if team:
breadcrumbs = build_team_breadcrumbs(request, team)
else:
breadcrumbs = build_home_breadcrumbs(request)
return {"breadcrumbs": breadcrumbs + extra_breadcrumbs}

# Build profile breadcrumbs
if has_profile_breadcrumbs:
Expand All @@ -67,5 +67,6 @@ def breadcrumbs(context) -> list[tuple[str, str]]:
breadcrumbs.append(
(reverse("profile-view", args=[profile.slug]), profile.full_name)
)
return {"breadcrumbs": breadcrumbs + extra_breadcrumbs}

return {"breadcrumbs": breadcrumbs + extra_breadcrumbs}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
<form method="get" class="content-stack large">
<div class="content-stack large">
<h1>{{ page_title }}</h1>
{% if team %}<input name="team" type="hidden" value="{{ team.pk }}" />{% endif %}
<input name="query"
placeholder="Search people"
type="search"
value="{{ search_query|default:'' }}">
</div>
<hr>
<div class="dwds-button-group">
<input class="dwds-button dwds-button--secondary dwds-button--inline"
type="submit"
value="Apply filters" />
<a href="?">Reset filters</a>
value="Search" />
</div>
</form>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/peoplefinder/templates/peoplefinder/person-directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{% block bookmark %}
{% endblock bookmark %}

{% block title %}
{{ page_title }}
{% endblock title %}

{% block page_title_wrapper %}
{% endblock page_title_wrapper %}

Expand Down
1 change: 1 addition & 0 deletions src/peoplefinder/templates/peoplefinder/team.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ <h2>People in {{ team.short_name }}</h2>
</div>
</details>
{% endif %}
<a href="{% url 'people-directory' %}?team={{ team.pk }}">Team Directory</a>
</div>
{% endblock primary_content %}
47 changes: 36 additions & 11 deletions src/peoplefinder/views/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db.models.query import QuerySet
from django.views.generic import ListView

from peoplefinder.models import Person
from peoplefinder.models import Person, Team
from search.search import PeopleSearchVector


Expand All @@ -13,27 +13,52 @@ class PeopleDirectory(ListView):
template_name = "peoplefinder/person-directory.html"
paginate_by = 30

def dispatch(self, request, *args, **kwargs):
self.query = self.request.GET.get("query", "")

self.team = None
if team_pk := self.request.GET.get("team", ""):
self.team = Team.objects.get(pk=team_pk)

return super().dispatch(request, *args, **kwargs)

def get_queryset(self) -> QuerySet[Any]:
query = self.request.GET.get("query", "")
if query:
if self.query:
people_results = PeopleSearchVector(self.request).search(
query_str=self.request.GET.get("query", "")
query_str=self.query
)
return people_results
person_ids = [p.id for p in people_results]
queryset = Person.objects.filter(id__in=person_ids)
else:
queryset = super().get_queryset()
if not self.request.user.has_perm(
"peoplefinder.can_view_inactive_profiles"
):
days = settings.SEARCH_SHOW_INACTIVE_PROFILES_WITHIN_DAYS
queryset = queryset.active_or_inactive_within(days=days)

queryset = super().get_queryset()
if self.team:
queryset = queryset.filter(
roles__team__pk__in=[self.team.pk]
+ [tt.child.pk for tt in self.team.parents.all()]
)
print(self.team.parents.all())
print(self.team.children.all())

if not self.request.user.has_perm("peoplefinder.can_view_inactive_profiles"):
days = settings.SEARCH_SHOW_INACTIVE_PROFILES_WITHIN_DAYS
queryset = queryset.active_or_inactive_within(days=days)
return queryset

def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
page_title = "Find people"

if self.team:
page_title = f"Find people in {self.team}"

context.update(
page_title="Find people",
page_title=page_title,
team=self.team,
team_breadcrumbs=True,
extra_breadcrumbs=[
("/", "Home"),
(None, "People directory"),
],
search_query=self.request.GET.get("query", ""),
Expand Down

0 comments on commit 85bf8f8

Please sign in to comment.