Enhance NormalCase functionality: prepopulate age fields on edit, update author handling in create case normal view, and refine template logic for editing permissions
This commit is contained in:
+17
-1
@@ -298,6 +298,22 @@ class NormalCaseForm(ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# If editing an existing NormalCase, prepopulate age_value/age_unit
|
||||
try:
|
||||
instance = kwargs.get('instance')
|
||||
except Exception:
|
||||
instance = None
|
||||
if instance is None:
|
||||
# also support self.instance when ModelForm sets it
|
||||
instance = getattr(self, 'instance', None)
|
||||
if instance is not None and getattr(instance, 'age_days', None) is not None:
|
||||
try:
|
||||
val, unit = NormalCase.days_to_value_unit(instance.age_days)
|
||||
if val is not None and unit is not None:
|
||||
self.fields['age_value'].initial = val
|
||||
self.fields['age_unit'].initial = unit
|
||||
except Exception:
|
||||
pass
|
||||
self.helper = FormHelper()
|
||||
# Do not render a <form> tag from crispy here because the template
|
||||
# already provides the surrounding form element (we inject this
|
||||
@@ -315,7 +331,7 @@ class NormalCaseForm(ModelForm):
|
||||
css_class="row",
|
||||
),
|
||||
Field("notes"),
|
||||
Submit("submit", "Save", css_class="btn btn-primary"),
|
||||
# Submit button rendered in modal footer; avoid duplicate button here
|
||||
)
|
||||
|
||||
def save(self, commit=True):
|
||||
|
||||
Reference in New Issue
Block a user