From 39d12d52f7025cba8a90ec1ee21a9fb507eaa583 Mon Sep 17 00:00:00 2001 From: eatyourpeas Date: Thu, 6 Jun 2024 09:43:57 +0100 Subject: [PATCH] fix npda_users get request not being called --- project/npda/templates/npda_users.html | 2 +- .../templates/partials/npda_user_table.html | 2 +- .../templates/partials/view_preference.html | 2 +- project/npda/views/npda_users.py | 18 +++++++++++------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/project/npda/templates/npda_users.html b/project/npda/templates/npda_users.html index 41bb4d73..129d4384 100644 --- a/project/npda/templates/npda_users.html +++ b/project/npda/templates/npda_users.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load static %} {% block content %} -
+
{% url 'npda_users' as hx_post %} diff --git a/project/npda/templates/partials/npda_user_table.html b/project/npda/templates/partials/npda_user_table.html index 101a76ca..e3363ecd 100644 --- a/project/npda/templates/partials/npda_user_table.html +++ b/project/npda/templates/partials/npda_user_table.html @@ -1,6 +1,6 @@ {% load npda_tags %} {% if npdauser_list %} - +
diff --git a/project/npda/templates/partials/view_preference.html b/project/npda/templates/partials/view_preference.html index a74e089d..b7ba37c6 100644 --- a/project/npda/templates/partials/view_preference.html +++ b/project/npda/templates/partials/view_preference.html @@ -4,7 +4,7 @@ {% if request.user.is_superuser or request.user.is_rcpch_audit_team_member or request.user.is_rcpch_staff %} - + {% endif %}
diff --git a/project/npda/views/npda_users.py b/project/npda/views/npda_users.py index f244ac6e..6133e57f 100644 --- a/project/npda/views/npda_users.py +++ b/project/npda/views/npda_users.py @@ -59,9 +59,9 @@ def get_queryset(self): if self.request.user.view_preference == 0: # organisation view ods_code = self.request.session.get("ods_code") - return NPDAUser.objects.filter( - site__organisation_ods_code=ods_code - ).order_by("surname") + return NPDAUser.objects.filter(organisation_employer=ods_code).order_by( + "surname" + ) elif self.request.user.view_preference == 1: # PDU view # create a list of sibling organisations' ODS codes who share the same PDU as the user @@ -83,11 +83,11 @@ def get_queryset(self): def get_context_data(self, **kwargs): context = super(NPDAUserListView, self).get_context_data(**kwargs) context["title"] = "NPDA Users" - user_pz_code = self.request.session.get("sibling_organisations", {}).get( + pz_code = self.request.session.get("sibling_organisations", {}).get( "pz_code", None ) - context["pz_code"] = user_pz_code - context["ods_code"] = self.request.user.organisation_employer + context["pz_code"] = pz_code + context["ods_code"] = self.request.session.get("ods_code") context["organisation_choices"] = self.request.session.get( "organisation_choices" ) @@ -103,6 +103,7 @@ def get(self, request, *args: str, **kwargs) -> HttpResponse: # filter the npdausers to only those in the same organisation as the user # trigger a GET request from the patient table to update the list of npdausers # by calling the get_queryset method again with the new ods_code/pz_code stored in session + logger.warning("HTMX request received") queryset = self.get_queryset() context = self.get_context_data() context["npdauser_list"] = queryset @@ -187,7 +188,7 @@ def post(self, request, *args: str, **kwargs) -> HttpResponse: response = render(request, "partials/view_preference.html", context=context) trigger_client_event( - response=response, name="patients", params={} + response=response, name="npda_users", params={} ) # reloads the form to show the active steps return response @@ -410,6 +411,9 @@ def post(self, *args, **kwargs): sibling_organisations ) + if "ods_code" not in self.request.session: + self.request.session["ods_code"] = current_user_ods_code + if "organisation_choices" not in self.request.session: # get all NHS organisations in user's PDU as list of tuples (ODS code, name) self.request.session["organisation_choices"] = [
NPDA UserID