# Path: django_sonic_screwdriver/settings.py
# USER_SETTINGS = getattr(settings, "SONIC_SCREWDRIVER", None)
# DEFAULTS = {
#     "DEBUG": False,
#     # Returns file where the version number is located
#     "VERSION_FILE": "setup.py",
#     "RELEASE_SEPARATOR": "",
#     "PATCH_AUTO_TAG": False,
#     # Git
#     "GIT_DIR": settings.BASE_DIR,
#     # Git Tagging
#     "GIT_TAG_AUTO_TAG_PUSH": False,
#     "GIT_STAGING_PRE_TAG": "staging",
#     "GIT_ACTIVATE_PRE_TAG": "activate",
#     "SECURE_TAGGING": True,
#     # App Ban
#     "BAN_REMOTE_ADDR_HEADER": "REMOTE_ADDR",
#     "BAN_DEFAULT_END_TIME": 60 * 60,
# }
# class APISettings(object):
#     def __init__(self, user_settings=None, defaults=None):
#     def __getattr__(self, attr):
# 
# Path: django_sonic_screwdriver/apps/ban/models.py
# class UserBan(Ban):
#     banned_user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         on_delete=models.CASCADE,
#         verbose_name=_("User"),
#         related_name="banned_user",
#         blank=False,
#         null=True,
#         help_text="This is the banned user or the receiver of the ban.",
#     )
# 
#     class Meta:
#         verbose_name = _("User Ban")
#         verbose_name_plural = _("User Bans")
# 
#     def __str__(self):
#         return self.banned_user.get_username()
# 
# class IPBan(Ban):
#     ip = models.GenericIPAddressField(
#         verbose_name=_("IP"),
#         blank=False,
#         null=True,
#         help_text=_(
#             "This is the banned ip. Every request from this IP will result in 403."
#         ),
#     )
# 
#     class Meta:
#         verbose_name = _("IP Ban")
#         verbose_name_plural = _("IP Bans")
# 
#     def __str__(self):
#         return str(self.ip)


from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from django.http import HttpResponseForbidden
from django.utils import timezone
from django_sonic_screwdriver.settings import api_settings
from .models import UserBan, IPBan




class BanMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response


# Path: django_sonic_screwdriver/settings.py
# USER_SETTINGS = getattr(settings, "SONIC_SCREWDRIVER", None)
# DEFAULTS = {
#     "DEBUG": False,
#     # Returns file where the version number is located
#     "VERSION_FILE": "setup.py",
#     "RELEASE_SEPARATOR": "",
#     "PATCH_AUTO_TAG": False,
#     # Git
#     "GIT_DIR": settings.BASE_DIR,
#     # Git Tagging
#     "GIT_TAG_AUTO_TAG_PUSH": False,
#     "GIT_STAGING_PRE_TAG": "staging",
#     "GIT_ACTIVATE_PRE_TAG": "activate",
#     "SECURE_TAGGING": True,
#     # App Ban
#     "BAN_REMOTE_ADDR_HEADER": "REMOTE_ADDR",
#     "BAN_DEFAULT_END_TIME": 60 * 60,
# }
# class APISettings(object):
#     def __init__(self, user_settings=None, defaults=None):
#     def __getattr__(self, attr):
# 
# Path: django_sonic_screwdriver/apps/ban/models.py
# class UserBan(Ban):
#     banned_user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         on_delete=models.CASCADE,
#         verbose_name=_("User"),
#         related_name="banned_user",
#         blank=False,
#         null=True,
#         help_text="This is the banned user or the receiver of the ban.",
#     )
# 
#     class Meta:
#         verbose_name = _("User Ban")
#         verbose_name_plural = _("User Bans")
# 
#     def __str__(self):
#         return self.banned_user.get_username()
# 
# class IPBan(Ban):
#     ip = models.GenericIPAddressField(
#         verbose_name=_("IP"),
#         blank=False,
#         null=True,
#         help_text=_(
#             "This is the banned ip. Every request from this IP will result in 403."
#         ),
#     )
# 
#     class Meta:
#         verbose_name = _("IP Ban")
#         verbose_name_plural = _("IP Bans")
# 
#     def __str__(self):
#         return str(self.ip)


# Path: django_sonic_screwdriver/apps/ban/middleware.py
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from django.http import HttpResponseForbidden
from django.utils import timezone
from django_sonic_screwdriver.settings import api_settings
from .models import UserBan, IPBan





class BanMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response


    def __call__(self, request):