Refactor templates and views for improved structure and maintainability

This commit is contained in:
Ross
2025-12-08 12:31:58 +00:00
parent ad5e7aeed8
commit d7afab15e1
5 changed files with 242 additions and 83 deletions
+27
View File
@@ -5490,11 +5490,38 @@ class ExamCollectionEdit(UpdateView, AuthorRequiredMixin):
model = ExamCollection
form_class = ExamCollectionForm
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Ensure we have a bound form to extract bound fields
form = kwargs.get('form') or self.get_form()
groups = []
for label, field_name, model in getattr(self.form_class, 'GROUP_TYPES', []):
try:
bound = form[field_name]
except Exception:
bound = None
groups.append((label, field_name, bound))
context['exam_groups'] = groups
return context
class ExamCollectionCreate(CreateView, AuthorRequiredMixin):
model = ExamCollection
form_class = ExamCollectionForm
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
form = kwargs.get('form') or self.get_form()
groups = []
for label, field_name, model in getattr(self.form_class, 'GROUP_TYPES', []):
try:
bound = form[field_name]
except Exception:
bound = None
groups.append((label, field_name, bound))
context['exam_groups'] = groups
return context
class ExamCollectionClone(CreateView, AuthorRequiredMixin):
model = ExamCollection