approval.forms.monitored

Form mixins for approvable models.

 1"""Form mixins for approvable models."""
 2from django.utils.translation import pgettext_lazy
 3
 4from ..models import MonitoredModel
 5import logging
 6
 7logger = logging.getLogger("approval")
 8
 9
10class MonitoredForm:
11    """ModelForm mixin for monitored models."""
12
13    def __init__(self, *args, **kwargs):
14        """
15        Form initializer for ApprovedModel.
16
17        The form is initialized with the instance data fetched from the sandbox,
18        so you can start editing the object from your last attempt.
19        """
20        instance = kwargs.get("instance", None)
21        if instance and isinstance(instance, MonitoredModel):
22            if getattr(instance, "approval", None) and instance.approval.approved is None:
23                instance.approval._update_source()
24                logger.debug(pgettext_lazy("approval", f"{self.__class__.__name__} fetched approval data for form."))
25        super().__init__(*args, **kwargs)
logger = <Logger approval (DEBUG)>
class MonitoredForm:
11class MonitoredForm:
12    """ModelForm mixin for monitored models."""
13
14    def __init__(self, *args, **kwargs):
15        """
16        Form initializer for ApprovedModel.
17
18        The form is initialized with the instance data fetched from the sandbox,
19        so you can start editing the object from your last attempt.
20        """
21        instance = kwargs.get("instance", None)
22        if instance and isinstance(instance, MonitoredModel):
23            if getattr(instance, "approval", None) and instance.approval.approved is None:
24                instance.approval._update_source()
25                logger.debug(pgettext_lazy("approval", f"{self.__class__.__name__} fetched approval data for form."))
26        super().__init__(*args, **kwargs)

ModelForm mixin for monitored models.

MonitoredForm(*args, **kwargs)
14    def __init__(self, *args, **kwargs):
15        """
16        Form initializer for ApprovedModel.
17
18        The form is initialized with the instance data fetched from the sandbox,
19        so you can start editing the object from your last attempt.
20        """
21        instance = kwargs.get("instance", None)
22        if instance and isinstance(instance, MonitoredModel):
23            if getattr(instance, "approval", None) and instance.approval.approved is None:
24                instance.approval._update_source()
25                logger.debug(pgettext_lazy("approval", f"{self.__class__.__name__} fetched approval data for form."))
26        super().__init__(*args, **kwargs)

Form initializer for ApprovedModel.

The form is initialized with the instance data fetched from the sandbox, so you can start editing the object from your last attempt.