# Path: django_sonic_screwdriver/models.py
# class BaseModel(models.Model):
#     created_at = models.DateTimeField(
#         verbose_name=_("Created at"),
#         auto_now_add=True,
#         blank=False,
#         null=False,
#         help_text=_("Model was created at this time."),
#     )
# 
#     updated_at = models.DateTimeField(
#         verbose_name=_("Updated at"),
#         auto_now=True,
#         blank=False,
#         null=False,
#         help_text=_("Model was updated at this time."),
#     )
# 
#     objects = BaseManager()
# 
#     class Meta:
#         abstract = True
# 
# class BaseManager(models.Manager):
#     def get_or_404(self, *args, **kwargs):
#         """
#         Returns instance or raises 404.
#         """
#         try:
#             instance = super(BaseManager, self).get(*args, **kwargs)
#         except self.model.DoesNotExist:
#             from .exceptions import NotFoundException
# 
#             raise NotFoundException
#         return instance
# 
# 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):


from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django_sonic_screwdriver.models import BaseModel, BaseManager
from django_sonic_screwdriver.settings import api_settings



class BanManager(BaseManager):
    def create_for_user(self, banned_user, end_date=None, *args, **kwargs):
        """
        Creates a ban for an user.
        The default ban time is 1 hour.
        """
        kwargs["banned_user"] = banned_user
        kwargs["end_date"] = end_date if end_date else self.__get_default_end_date()
        return super(BanManager, self).create(*args, **kwargs)

    def create_for_ip(self, ip, end_date=None, *args, **kwargs):
        """
        Creates a ban for an ip.
        The default ban time is 1 hour.
        """
        kwargs["ip"] = ip
        kwargs["end_date"] = end_date if end_date else self.__get_default_end_date()
        return super(BanManager, self).create(*args, **kwargs)

    @staticmethod
    def __get_default_end_date():
        return timezone.now() + timezone.timedelta(

# Path: django_sonic_screwdriver/models.py
# class BaseModel(models.Model):
#     created_at = models.DateTimeField(
#         verbose_name=_("Created at"),
#         auto_now_add=True,
#         blank=False,
#         null=False,
#         help_text=_("Model was created at this time."),
#     )
# 
#     updated_at = models.DateTimeField(
#         verbose_name=_("Updated at"),
#         auto_now=True,
#         blank=False,
#         null=False,
#         help_text=_("Model was updated at this time."),
#     )
# 
#     objects = BaseManager()
# 
#     class Meta:
#         abstract = True
# 
# class BaseManager(models.Manager):
#     def get_or_404(self, *args, **kwargs):
#         """
#         Returns instance or raises 404.
#         """
#         try:
#             instance = super(BaseManager, self).get(*args, **kwargs)
#         except self.model.DoesNotExist:
#             from .exceptions import NotFoundException
# 
#             raise NotFoundException
#         return instance
# 
# 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
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django_sonic_screwdriver.models import BaseModel, BaseManager
from django_sonic_screwdriver.settings import api_settings




class BanManager(BaseManager):
    def create_for_user(self, banned_user, end_date=None, *args, **kwargs):
        """
        Creates a ban for an user.
        The default ban time is 1 hour.
        """
        kwargs["banned_user"] = banned_user
        kwargs["end_date"] = end_date if end_date else self.__get_default_end_date()
        return super(BanManager, self).create(*args, **kwargs)

    def create_for_ip(self, ip, end_date=None, *args, **kwargs):
        """
        Creates a ban for an ip.
        The default ban time is 1 hour.
        """
        kwargs["ip"] = ip
        kwargs["end_date"] = end_date if end_date else self.__get_default_end_date()
        return super(BanManager, self).create(*args, **kwargs)

    @staticmethod
    def __get_default_end_date():
        return timezone.now() + timezone.timedelta(

            seconds=api_settings.BAN_DEFAULT_END_TIME