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:
|
||||
model = Procedure
|
||||
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):
|
||||
@@ -624,6 +634,7 @@ class CaseForm(ModelForm):
|
||||
"presentation",
|
||||
"discussion",
|
||||
"report",
|
||||
"procedures",
|
||||
"condition",
|
||||
"pathological_process",
|
||||
"open_access",
|
||||
@@ -655,6 +666,7 @@ class CaseForm(ModelForm):
|
||||
"history",
|
||||
"presentation",
|
||||
"discussion",
|
||||
"procedures",
|
||||
"condition",
|
||||
"pathological_process",
|
||||
"report",
|
||||
@@ -684,6 +696,9 @@ class CaseForm(ModelForm):
|
||||
"subspecialty": CheckboxSelectMultiple(),
|
||||
"pathological_process": CheckboxSelectMultiple(),
|
||||
"previous_case": CaseSelect(),
|
||||
"procedures": autocomplete.ModelSelect2Multiple(
|
||||
url="atlas:procedure-autocomplete"
|
||||
),
|
||||
}
|
||||
|
||||
def clean_cimar_uuid(self):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{% extends 'atlas/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<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>
|
||||
<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>
|
||||
<ul>
|
||||
<li><a href="{% url 'atlas:condition_view' %}">Conditions</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>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 %}
|
||||
{% crispy form %}
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -2769,6 +2769,14 @@ class ProcedureCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
model = Procedure
|
||||
form_class = ProcedureForm
|
||||
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):
|
||||
self.object = form.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
Reference in New Issue
Block a user