2019-10-14 13:00:20 +00:00
|
|
|
"""policy structures"""
|
2019-10-07 14:33:48 +00:00
|
|
|
from __future__ import annotations
|
2019-10-07 14:50:13 +00:00
|
|
|
|
2020-02-18 21:12:51 +00:00
|
|
|
from typing import TYPE_CHECKING, Tuple
|
2019-10-03 08:45:31 +00:00
|
|
|
|
2019-10-28 16:40:57 +00:00
|
|
|
from django.db.models import Model
|
2019-10-03 08:45:31 +00:00
|
|
|
from django.http import HttpRequest
|
|
|
|
|
2019-10-04 07:50:25 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from passbook.core.models import User
|
2019-10-03 08:45:31 +00:00
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
|
2019-10-03 08:45:31 +00:00
|
|
|
class PolicyRequest:
|
|
|
|
"""Data-class to hold policy request data"""
|
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
user: User
|
2019-10-03 08:45:31 +00:00
|
|
|
http_request: HttpRequest
|
2019-10-28 16:40:57 +00:00
|
|
|
obj: Model
|
2019-10-03 08:45:31 +00:00
|
|
|
|
2019-10-07 14:33:48 +00:00
|
|
|
def __init__(self, user: User):
|
2019-10-03 08:45:31 +00:00
|
|
|
self.user = user
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"<PolicyRequest user={self.user}>"
|
|
|
|
|
|
|
|
|
|
|
|
class PolicyResult:
|
|
|
|
"""Small data-class to hold policy results"""
|
|
|
|
|
2020-02-18 21:12:51 +00:00
|
|
|
passing: bool
|
|
|
|
messages: Tuple[str]
|
2019-10-03 08:45:31 +00:00
|
|
|
|
|
|
|
def __init__(self, passing: bool, *messages: str):
|
|
|
|
self.passing = passing
|
|
|
|
self.messages = messages
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"<PolicyResult passing={self.passing}>"
|