File: forms.py

package info (click to toggle)
python-django-braces 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 484 kB
  • sloc: python: 2,680; makefile: 138; sh: 6
file content (14 lines) | stat: -rw-r--r-- 528 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class UserKwargModelFormMixin:
    """
    Generic model form mixin for popping user out of the kwargs and
    attaching it to the instance.

    This mixin must precede forms.ModelForm/forms.Form. The form is not
    expecting these kwargs to be passed in, so they must be popped off before
    anything else is done.
    """

    def __init__(self, *args, **kwargs):
        """Remove the user from **kwargs and assign it on the object"""
        self.user = kwargs.pop("user", None)
        super().__init__(*args, **kwargs)