approval.templatetags.approval API documentation

# approval.templatetags.approval

View Source

     1from typing import Optional
     2
     3from django import template
     4from ..models import MonitoredModel
     5
     6register = template.Library()
     7
     8
     9@register.filter(name="approval_pending")
    10def is_approval_pending(instance: MonitoredModel) -> Optional[bool]:
    11    """
    12    Get whether the instance has an approval pending.
    13
    14    Returns:
    15        `True`: if the object has changes pending.
    16        `False`: if the object has nothing pending.
    17        `None`: if the object is not a `MonitoredModel` instance.
    18    """
    19    if isinstance(instance, MonitoredModel):
    20        if hasattr(instance, "approval"):
    21            if instance.approval.approved is None:
    22                return True
    23        return False
    24    return None
    25
    26
    27@register.filter(name="approval_denied")
    28def is_approval_denied(instance: MonitoredModel) -> Optional[bool]:
    29    """
    30    Get whether the instance approval was rejected.
    31
    32    Returns:
    33        `True`: if the object has changes rejected.
    34        `False`: if the object is not in that case.
    35        `None`: if the object is not a `MonitoredModel` instance.
    36    """
    37    if isinstance(instance, MonitoredModel):
    38        if hasattr(instance, "approval"):
    39            if instance.approval.approved is False:
    40                return True
    41        return False
    42    return None

register = <django.template.library.Library object>
@register.filter(name='approval_pending')
def is_approval_pending(instance: approval.models.monitored.MonitoredModel) -> Optional[bool]: View Source

    10@register.filter(name="approval_pending")
    11def is_approval_pending(instance: MonitoredModel) -> Optional[bool]:
    12    """
    13    Get whether the instance has an approval pending.
    14
    15    Returns:
    16        `True`: if the object has changes pending.
    17        `False`: if the object has nothing pending.
    18        `None`: if the object is not a `MonitoredModel` instance.
    19    """
    20    if isinstance(instance, MonitoredModel):
    21        if hasattr(instance, "approval"):
    22            if instance.approval.approved is None:
    23                return True
    24        return False
    25    return None

Get whether the instance has an approval pending.

Returns: `True`: if the object has changes pending. `False`: if the object has nothing pending. `None`: if the object is not a `MonitoredModel` instance.

@register.filter(name='approval_denied')
def is_approval_denied(instance: approval.models.monitored.MonitoredModel) -> Optional[bool]: View Source

    28@register.filter(name="approval_denied")
    29def is_approval_denied(instance: MonitoredModel) -> Optional[bool]:
    30    """
    31    Get whether the instance approval was rejected.
    32
    33    Returns:
    34        `True`: if the object has changes rejected.
    35        `False`: if the object is not in that case.
    36        `None`: if the object is not a `MonitoredModel` instance.
    37    """
    38    if isinstance(instance, MonitoredModel):
    39        if hasattr(instance, "approval"):
    40            if instance.approval.approved is False:
    41                return True
    42        return False
    43    return None

Get whether the instance approval was rejected.

Returns: `True`: if the object has changes rejected. `False`: if the object is not in that case. `None`: if the object is not a `MonitoredModel` instance.