Add NormalCase form and related views for managing normal cases
This commit is contained in:
+28
-8
@@ -44,6 +44,7 @@ from atlas.models import (
|
||||
UserReportAnswer,
|
||||
CaseDisplaySet,
|
||||
)
|
||||
from .models import NormalCase
|
||||
|
||||
from anatomy.models import Modality
|
||||
|
||||
@@ -236,6 +237,28 @@ class CaseCollectionForm(ModelForm):
|
||||
Submit("submit", "Save Collection", css_class="btn btn-primary"),
|
||||
)
|
||||
|
||||
|
||||
class NormalCaseForm(ModelForm):
|
||||
class Meta:
|
||||
model = NormalCase
|
||||
fields = ("age_years", "examination", "modality", "notes")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_method = "post"
|
||||
self.helper.form_tag = True
|
||||
self.helper.layout = Layout(
|
||||
Div(
|
||||
Field("age_years", wrapper_class="col-md-4"),
|
||||
Field("examination", wrapper_class="col-md-4"),
|
||||
Field("modality", wrapper_class="col-md-4"),
|
||||
css_class="row",
|
||||
),
|
||||
Field("notes"),
|
||||
Submit("submit", "Save", css_class="btn btn-primary"),
|
||||
)
|
||||
|
||||
self.fields["start_date"] = SplitDateTimeFieldDefaultTime(
|
||||
widget=SplitDateTimeWidget(
|
||||
date_attrs={"type": "date", "class": "datepicker"},
|
||||
@@ -258,14 +281,11 @@ class CaseCollectionForm(ModelForm):
|
||||
)
|
||||
|
||||
def save(self, commit=True):
|
||||
# Get the unsaved Case instance
|
||||
instance = ModelForm.save(self, False)
|
||||
|
||||
# Do we need to save all changes now?
|
||||
# if commit:
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
|
||||
# Respect the commit flag: return an unsaved instance if commit=False
|
||||
instance = super().save(commit=False)
|
||||
if commit:
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
return instance
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user