# 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
        the view is called.

        :param request:
        :param response:
        :return:
        """
        return request, response

    def __user_ban_exists(self, request):
        """
        Get the user and try to find a ban for the user.

        :param: request
        """
        if not isinstance(request.user, AnonymousUser):
            return (
                UserBan.objects.filter(banned_user=request.user)
                .filter(Q(end_date__gte=timezone.now()) | Q(end_date__exact=None))
                .exists()
            )

    def __ip_ban_exists(self, request):
        """
        Get the ip_address of the request and try to find a ban
        with this ip.

        :param: request
        """
        ip_address = request.META.get(api_settings.BAN_REMOTE_ADDR_HEADER)
        return (

# 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

        the view is called.

        :param request:
        :param response:
        :return:
        """
        return request, response

    def __user_ban_exists(self, request):
        """
        Get the user and try to find a ban for the user.

        :param: request
        """
        if not isinstance(request.user, AnonymousUser):
            return (
                UserBan.objects.filter(banned_user=request.user)
                .filter(Q(end_date__gte=timezone.now()) | Q(end_date__exact=None))
                .exists()
            )

    def __ip_ban_exists(self, request):
        """
        Get the ip_address of the request and try to find a ban
        with this ip.

        :param: request
        """
        ip_address = request.META.get(api_settings.BAN_REMOTE_ADDR_HEADER)
        return (

            IPBan.objects.filter(ip=ip_address)