Skip to content

Commit

Permalink
document FormsetView
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmohrin committed Oct 2, 2023
1 parent 6dfe419 commit f326956
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions evap/evaluation/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,23 @@ def assert_not_none(value: T | None) -> T:


class FormsetView(FormView):
"""
Just like `FormView`, but with a renaming from "form" to "formset".
"""

@property
def form_class(self):
return self.formset_class

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["formset"] = context.pop("form")
return context

# As an example for the logic, consider the following: Django calls `get_form_kwargs`, which we delegate to
# `get_formset_kwargs`. Users can thus override `get_formset_kwargs` instead. If it is not overridden, we delegate
# to the original `get_form_kwargs` instead. The same approach is used for the other renamed methods.

def get_form_kwargs(self):
return self.get_formset_kwargs()

Expand All @@ -156,11 +169,6 @@ def form_valid(self, form):
def formset_valid(self, formset):
return super().form_valid(formset)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["formset"] = context.pop("form")
return context


class SaveValidFormMixin:
def form_valid(self, form):
Expand Down

0 comments on commit f326956

Please sign in to comment.