Skip to content

Commit

Permalink
refactor submissions to object list
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourpeas committed Jul 30, 2024
1 parent 7183b5c commit 7b79d29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion project/npda/templates/submissions_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="inline-block min-w-full py-2 sm:px-6 lg:px-8">
<div class="relative overflow-x-auto">
<strong>All Submissions for {{pz_code}}</strong>
{% include 'partials/submission_history.html' with submissions=submissions %}
{% include 'partials/submission_history.html' with submissions=object_list %}
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion project/npda/views/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ class PatientUpdateView(
success_url = reverse_lazy("patients")

def get_context_data(self, **kwargs):
PaediatricDiabetesUnit = apps.get_model("npda", "PaediatricDiabetesUnit")
Transfer = apps.get_model("npda", "Transfer")
patient = Patient.objects.get(pk=self.kwargs["pk"])

Expand Down
27 changes: 9 additions & 18 deletions project/npda/views/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def get_queryset(self) -> Iterable[Any]:
:return: The queryset for the view
"""
PaediatricDiabetesUnit = apps.get_model(
app_label="npda", model_name="PaediatricDiabetesUnit"
)
pdu, created = PaediatricDiabetesUnit.objects.get_or_create(
pz_code=self.request.session.get("pz_code"),
ods_code=self.request.session.get("ods_code"),
)
queryset = (
self.model.objects.filter(
pz_code=self.request.session.get("pz_code"),
ods_code=self.request.session.get("ods_code"),
)
.values("submission_date", "pz_code", "ods_code", "quarter", "audit_year")
self.model.objects.filter(paediatric_diabetes_unit=pdu)
.values("submission_date", "quarter", "audit_year")
.annotate(
patient_count=Count("patients"),
submission_active=F("submission_active"),
Expand All @@ -48,8 +52,6 @@ def get_queryset(self) -> Iterable[Any]:
)
.order_by(
"-submission_date",
"pz_code",
"ods_code",
"audit_year",
"quarter",
"submission_active",
Expand All @@ -68,17 +70,6 @@ def get_context_data(self, **kwargs: Any) -> dict:
context["pz_code"] = self.request.session.get("pz_code")
return context

def get(self, request, *args, **kwargs):
"""
Handle the GET request.
:param request: The request
:param args: The arguments
:param kwargs: The keyword arguments
:return: The response
"""
return super().get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
"""
Handle the POST request.
Expand Down

0 comments on commit 7b79d29

Please sign in to comment.