From e9dfd3b2a5e788605b0debf9d104357ea7efb633 Mon Sep 17 00:00:00 2001 From: ismail Date: Wed, 17 Jun 2026 20:37:30 +0300 Subject: [PATCH] fix: 3 create-page bugs (missing template, bad reverse, form instance access) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. /complaints/templates/new/ — TemplateDoesNotExist: template_form.html was missing. Created a functional template form (name, category, title pattern, description). 2. /complaints/oncall/schedules/new/ — NoReverseMatch: redirect('dashboard') should be redirect('/') since the URL name 'dashboard' doesn't exist. 3. /complaints/settings/escalation-rules/new/ — RelatedObjectDoesNotExist: EscalationRuleForm accessed self.instance.hospital on an unsaved instance. Changed to self.instance.hospital_id (safe FK ID check). --- apps/complaints/forms.py | 2 +- apps/complaints/ui_views_oncall.py | 2 +- .../complaints/templates/template_form.html | 63 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 templates/complaints/templates/template_form.html diff --git a/apps/complaints/forms.py b/apps/complaints/forms.py index 937ab26..aae7680 100644 --- a/apps/complaints/forms.py +++ b/apps/complaints/forms.py @@ -904,7 +904,7 @@ class EscalationRuleForm(HospitalFieldMixin, forms.ModelForm): pass elif self.initial.get("hospital"): hospital = self.initial.get("hospital") - elif self.instance and self.instance.pk and self.instance.hospital: + elif self.instance and self.instance.pk and self.instance.hospital_id: hospital = self.instance.hospital elif self.user and self.user.is_px_admin(): hospital = getattr(self.request, "tenant_hospital", None) diff --git a/apps/complaints/ui_views_oncall.py b/apps/complaints/ui_views_oncall.py index a180584..1eb2e59 100644 --- a/apps/complaints/ui_views_oncall.py +++ b/apps/complaints/ui_views_oncall.py @@ -29,7 +29,7 @@ def check_px_admin(request): """Check if user is PX Admin, return redirect if not.""" if not request.user.is_px_admin(): messages.error(request, _("You do not have permission to access this page.")) - return redirect("dashboard") + return redirect("/") return None diff --git a/templates/complaints/templates/template_form.html b/templates/complaints/templates/template_form.html new file mode 100644 index 0000000..04aaf80 --- /dev/null +++ b/templates/complaints/templates/template_form.html @@ -0,0 +1,63 @@ +{% extends "layouts/base.html" %} +{% load i18n %} + +{% block title %}{% if template %}{% trans "Edit Template" %}{% else %}{% trans "New Template" %}{% endif %} - PX360{% endblock %} + +{% block content %} +
+
+
+ {% trans "Templates" %} + + {% if template %}{% trans "Edit" %}{% else %}{% trans "New" %}{% endif %} +
+

{% if template %}{% trans "Edit Template" %}{% else %}{% trans "Create Template" %}{% endif %}

+
+ +
+
+ {% csrf_token %} + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + {% trans "Cancel" %} + +
+
+
+
+{% endblock %}