Enhance ProcedureForm and ProcedureCreate: add form helper initialization, update procedure form action URL, and implement logging in dispatch method
This commit is contained in:
@@ -400,6 +400,16 @@ class ProcedureForm(ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Procedure
|
model = Procedure
|
||||||
exclude = []
|
exclude = []
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
try:
|
||||||
|
self.helper = FormHelper()
|
||||||
|
self.helper.form_method = "post"
|
||||||
|
# Prevent crispy from rendering its own <form> tag so our
|
||||||
|
# template-level form wrapper contains the submit buttons.
|
||||||
|
self.helper.form_tag = False
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SeriesFindingForm(ModelForm):
|
class SeriesFindingForm(ModelForm):
|
||||||
@@ -624,6 +634,7 @@ class CaseForm(ModelForm):
|
|||||||
"presentation",
|
"presentation",
|
||||||
"discussion",
|
"discussion",
|
||||||
"report",
|
"report",
|
||||||
|
"procedures",
|
||||||
"condition",
|
"condition",
|
||||||
"pathological_process",
|
"pathological_process",
|
||||||
"open_access",
|
"open_access",
|
||||||
@@ -655,6 +666,7 @@ class CaseForm(ModelForm):
|
|||||||
"history",
|
"history",
|
||||||
"presentation",
|
"presentation",
|
||||||
"discussion",
|
"discussion",
|
||||||
|
"procedures",
|
||||||
"condition",
|
"condition",
|
||||||
"pathological_process",
|
"pathological_process",
|
||||||
"report",
|
"report",
|
||||||
@@ -684,6 +696,9 @@ class CaseForm(ModelForm):
|
|||||||
"subspecialty": CheckboxSelectMultiple(),
|
"subspecialty": CheckboxSelectMultiple(),
|
||||||
"pathological_process": CheckboxSelectMultiple(),
|
"pathological_process": CheckboxSelectMultiple(),
|
||||||
"previous_case": CaseSelect(),
|
"previous_case": CaseSelect(),
|
||||||
|
"procedures": autocomplete.ModelSelect2Multiple(
|
||||||
|
url="atlas:procedure-autocomplete"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def clean_cimar_uuid(self):
|
def clean_cimar_uuid(self):
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{% extends 'atlas/base.html' %}
|
{% extends 'atlas/base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Categories</h1>
|
<h1>Categories</h1>
|
||||||
<p>The platform has numberous different ways to tag and categorise content. These help with organsing cases and series, given the ability to find cases by a particuarly property (such as a finding) or find similar cases.</p><p>These can be browsed below.</p>
|
<p>The platform has numberous different ways to tag and categorise content. These help with organsing cases and series, given the ability to find cases by a particuarly property (such as a finding) or find similar cases.</p><p>These can be browsed below.</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{% url 'atlas:condition_view' %}">Conditions</a></li>
|
<li><a href="{% url 'atlas:condition_view' %}">Conditions</a></li>
|
||||||
<li><a href="{% url 'atlas:finding_view' %}">Findings</a></li>
|
<li><a href="{% url 'atlas:finding_view' %}">Findings</a></li>
|
||||||
|
|||||||
@@ -10,12 +10,12 @@
|
|||||||
<p>Use this form to create or edit a procedure.</p>
|
<p>Use this form to create or edit a procedure.</p>
|
||||||
<p>Please check if it already <a href='{% url "atlas:procedure_view" %}'>exists</a> before doing so!</p>
|
<p>Please check if it already <a href='{% url "atlas:procedure_view" %}'>exists</a> before doing so!</p>
|
||||||
|
|
||||||
<form action="" method="post" enctype="multipart/form-data" id="procedure-form">
|
<form action="{% url 'atlas:procedure_create' %}" method="post" enctype="multipart/form-data" id="procedure-form" onsubmit="console.log('procedure-form submit', this);">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% crispy form %}
|
{% crispy form %}
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<button type="submit" class="btn btn-primary">Submit</button>
|
<button type="submit" id="procedure-submit" class="btn btn-primary">Submit</button>
|
||||||
<a class="btn btn-secondary ms-2" href="{% url 'atlas:procedure_view' %}">Cancel</a>
|
<a class="btn btn-secondary ms-2" href="{% url 'atlas:procedure_view' %}">Cancel</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -2769,6 +2769,14 @@ class ProcedureCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
|||||||
model = Procedure
|
model = Procedure
|
||||||
form_class = ProcedureForm
|
form_class = ProcedureForm
|
||||||
template_name = "atlas/procedure_form.html"
|
template_name = "atlas/procedure_form.html"
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
logger.debug("ProcedureCreate dispatch: method=%s, user=%s", request.method, request.user)
|
||||||
|
if request.method == 'POST':
|
||||||
|
logger.debug("ProcedureCreate POST data: %s", request.POST.dict())
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Error logging ProcedureCreate dispatch")
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
Reference in New Issue
Block a user