Refactor templates and views for improved structure and maintainability
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user