Skip to content

Commit

Permalink
fix npda_users get request not being called
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourpeas committed Jun 6, 2024
1 parent 8d495c7 commit 39d12d5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion project/npda/templates/npda_users.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="flex flex-row min-h-screen justify-center px-10">
<div class="flex flex-row min-h-screen justify-center px-10" hx-get="/npda_users" hx-trigger="npda_users from:body" hx-target="#npda_user_table">
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 sm:px-6 lg:px-8">
{% url 'npda_users' as hx_post %}
Expand Down
2 changes: 1 addition & 1 deletion project/npda/templates/partials/npda_user_table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load npda_tags %}
{% if npdauser_list %}
<table class="table-auto w-full text-sm text-left rtl:text-right text-gray-500 text-gray-400 mb-5 font-montserrat" hx-trigger="npdauser_list from:body" hx-target="#npda_user_table">
<table class="table-auto w-full text-sm text-left rtl:text-right text-gray-500 text-gray-400 mb-5 font-montserrat">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 bg-rcpch_dark_blue text-white">
<tr>
<th scope="col" class="py-3 w-1/12">NPDA UserID</th>
Expand Down
2 changes: 1 addition & 1 deletion project/npda/templates/partials/view_preference.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<input hx-post="{{hx_post}}" hx-target="{{hx_target}}" hx-trigger="click" hx-swap="innerHTML" class="join-item btn bg-rcpch_light_blue hover:bg-rcpch_dark_blue text-white font-montserrat focus:bg-rcpch_pink border-rcpch_light_blue form-check-input form-checked:bg-red form-checked:text-white" type="radio" name="view_preference" value="0" aria-label="Organisation - {{ods_code}}" {% if view_preference == 0 %} checked {% endif %} />
<input hx-post="{{hx_post}}" hx-target="{{hx_target}}" hx-trigger="click" hx-swap="innerHTML" class="join-item btn bg-rcpch_light_blue hover:bg-rcpch_dark_blue text-white font-montserrat focus:bg-rcpch_pink border-rcpch_light_blue" type="radio" name="view_preference" value="1" aria-label="Paediatric Diabetes Unit - {{pz_code}}" {% if view_preference == 1 %} checked {% endif %} />
{% if request.user.is_superuser or request.user.is_rcpch_audit_team_member or request.user.is_rcpch_staff %}
<input hx-post="{{hx_post}}" hx-target="{{hx_target}}" hx-trigger="click" hx-swap="innerHTML" class="join-item btn bg-rcpch_light_blue hover:bg-rcpch_dark_blue text-white font-montserrat focus:bg-rcpch_pink border-rcpch_light_blue" type="radio" name="view_preference" value="3" aria-label="All" {% if view_preference == 3 %} checked {% endif %} />
<input hx-post="{{hx_post}}" hx-target="{{hx_target}}" hx-trigger="click" hx-swap="innerHTML" class="join-item btn bg-rcpch_light_blue hover:bg-rcpch_dark_blue text-white font-montserrat focus:bg-rcpch_pink border-rcpch_light_blue" type="radio" name="view_preference" value="2" aria-label="All" {% if view_preference == 2 %} checked {% endif %} />
{% endif %}
</div>
<div class="w-full max-w-custom">
Expand Down
18 changes: 11 additions & 7 deletions project/npda/views/npda_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
)
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"] = [
Expand Down

0 comments on commit 39d12d5

Please sign in to comment.