# Path: varnish_bans_manager/core/models/user.py
# class User(AbstractBaseUser, PermissionsMixin):
#     first_name = models.CharField(_('first name'), max_length=30, blank=True)
#     last_name = models.CharField(_('last name'), max_length=30, blank=True)
#     email = models.EmailField(_('email address'), unique=True)
#     is_staff = models.BooleanField(_('staff status'), default=False)
#     is_active = models.BooleanField(_('active'), default=True)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
# 
#     objects = UserManager()
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = []
# 
#     def get_full_name(self):
#         if self.first_name or self.last_name:
#             return ', '.join([self.last_name, self.first_name])
#         else:
#             return self.email
# 
#     def get_short_name(self):
#         return self.first_name if self.first_name else self.email
# 
#     human_name = property(get_full_name)
# 
#     def editable_user_permission_labels(self):
#         permissions = filter(
#             lambda permission: permission.codename in PERMISSIONS,
#             self.user_permissions.all())
#         return [PERMISSIONS[permission.codename] for permission in permissions]
# 
#     class Meta:
#         permissions = (
#             ('can_access_advanced_ban_submission',
#              'Access advanced ban submission form'),
#             ('can_access_expert_ban_submission',
#              'Access expert ban submission form'),
#             ('can_access_bans_submissions',
#              'Access bans submissions'),
#             ('can_access_bans_status',
#              'Access bans status'),
#             ('can_access_caches_management',
#              'Access caches management'),
#             ('can_access_users_management',
#              'Access users management'),
#             ('can_access_settings',
#              'Access settings'),
#         )
#         verbose_name = _('user')
#         verbose_name_plural = _('users')
# 
# Path: varnish_bans_manager/core/models/base.py
# class Model(models.Model):
#     '''
#     Custom base model class.
# 
#     Added functionality:
#         - Keep track of old values for fields coming from the
#           persistence layer (only for those present in
#           VBMMeta.trackable_field_names). This values will be
#           accesible using the get_previous method.
#         - Automatic file deletion on updates and deletes. For
#           updates to work, FileField fields will always be
#           automatically added to VBMMeta.trackable_field_names.
#           See Options.__init__
# 
#     '''
#     __metaclass__ = ModelBase
# 
#     objects = Manager()
# 
#     def __init__(self, *args, **kwargs):
#         super(Model, self).__init__(*args, **kwargs)
#         # Initialize old fields.
#         self._refresh_old_fields()
# 
#     def get_previous(self, field):
#         return self._old_fields.get(field, None)
# 
#     def save(self, *args, **kwargs):
#         super(Model, self).save(*args, **kwargs)
#         # Remove any old file no longer pointed by this instance.
#         for file_field_name in self._vbm_meta.file_field_names:
#             old_file = self.get_previous(file_field_name)
#             new_file = getattr(self, file_field_name)
#             if old_file and old_file != new_file:
#                 old_file.delete(save=False)
#         # Refresh old fields.
#         self._refresh_old_fields()
# 
#     def _reduced_state_black_list(self):
#         # Define which custom attributes will not be used when pickling
#         # the instance.
#         return ['_old_fields']
# 
#     def _complete_state(self):
#         # Reassign values for those attributes that were not pickled for
#         # being in the reduced_state_black_list.
#         self._refresh_old_fields()
# 
#     def _refresh_old_fields(self):
#         self._old_fields = {}
#         if self.id:
#             for field in self._vbm_meta.trackable_field_names:
#                 self._old_fields[field] = getattr(self, field)
# 
#     def __reduce__(self):
#         # Django doesn't call __getstate__ under certain circumstances (e.g.
#         # under the presence of deferred attributes), so we need to modify
#         # the current instance's __dict__ so that nothing extra gets pickled.
#         # It's the only thing that's going to work for sure.
#         full_dict = self.__dict__.copy()
#         for attr in self._reduced_state_black_list():
#             if attr in self.__dict__:
#                 del self.__dict__[attr]
#         result = super(Model, self).__reduce__()
#         self.__dict__ = full_dict
#         return result
# 
#     def __setstate__(self, state):
#         self.__dict__.update(state)
#         self._complete_state()
# 
#     class Meta:
#         abstract = True
# 
#     class VBMMeta:
#         '''
#         Default values for all custom meta options.
#         '''
#         trackable_field_names = ()


from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import ugettext_lazy as _
from varnish_bans_manager.core.models import User
from varnish_bans_manager.core.models.base import Model
    )
    launched_at = models.DateTimeField(
        null=False
    )
    ban_type = models.PositiveSmallIntegerField(
        null=False,
        choices=BAN_TYPE_CHOICES
    )
    expression = models.CharField(
        max_length=2048,
        null=False
    )
    target_content_type = models.ForeignKey(ContentType)
    target_id = models.PositiveIntegerField()
    target = GenericForeignKey('target_content_type', 'target_id')
    created_at = models.DateTimeField(
        auto_now_add=True,
        null=False
    )
    updated_at = models.DateTimeField(
        auto_now=True,
        null=False
    )

    def _human_ban_type_name(self):
        return dict(self.BAN_TYPE_CHOICES)[self.ban_type]

    human_ban_type_name = property(_human_ban_type_name)



# Path: varnish_bans_manager/core/models/user.py
# class User(AbstractBaseUser, PermissionsMixin):
#     first_name = models.CharField(_('first name'), max_length=30, blank=True)
#     last_name = models.CharField(_('last name'), max_length=30, blank=True)
#     email = models.EmailField(_('email address'), unique=True)
#     is_staff = models.BooleanField(_('staff status'), default=False)
#     is_active = models.BooleanField(_('active'), default=True)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
# 
#     objects = UserManager()
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = []
# 
#     def get_full_name(self):
#         if self.first_name or self.last_name:
#             return ', '.join([self.last_name, self.first_name])
#         else:
#             return self.email
# 
#     def get_short_name(self):
#         return self.first_name if self.first_name else self.email
# 
#     human_name = property(get_full_name)
# 
#     def editable_user_permission_labels(self):
#         permissions = filter(
#             lambda permission: permission.codename in PERMISSIONS,
#             self.user_permissions.all())
#         return [PERMISSIONS[permission.codename] for permission in permissions]
# 
#     class Meta:
#         permissions = (
#             ('can_access_advanced_ban_submission',
#              'Access advanced ban submission form'),
#             ('can_access_expert_ban_submission',
#              'Access expert ban submission form'),
#             ('can_access_bans_submissions',
#              'Access bans submissions'),
#             ('can_access_bans_status',
#              'Access bans status'),
#             ('can_access_caches_management',
#              'Access caches management'),
#             ('can_access_users_management',
#              'Access users management'),
#             ('can_access_settings',
#              'Access settings'),
#         )
#         verbose_name = _('user')
#         verbose_name_plural = _('users')
# 
# Path: varnish_bans_manager/core/models/base.py
# class Model(models.Model):
#     '''
#     Custom base model class.
# 
#     Added functionality:
#         - Keep track of old values for fields coming from the
#           persistence layer (only for those present in
#           VBMMeta.trackable_field_names). This values will be
#           accesible using the get_previous method.
#         - Automatic file deletion on updates and deletes. For
#           updates to work, FileField fields will always be
#           automatically added to VBMMeta.trackable_field_names.
#           See Options.__init__
# 
#     '''
#     __metaclass__ = ModelBase
# 
#     objects = Manager()
# 
#     def __init__(self, *args, **kwargs):
#         super(Model, self).__init__(*args, **kwargs)
#         # Initialize old fields.
#         self._refresh_old_fields()
# 
#     def get_previous(self, field):
#         return self._old_fields.get(field, None)
# 
#     def save(self, *args, **kwargs):
#         super(Model, self).save(*args, **kwargs)
#         # Remove any old file no longer pointed by this instance.
#         for file_field_name in self._vbm_meta.file_field_names:
#             old_file = self.get_previous(file_field_name)
#             new_file = getattr(self, file_field_name)
#             if old_file and old_file != new_file:
#                 old_file.delete(save=False)
#         # Refresh old fields.
#         self._refresh_old_fields()
# 
#     def _reduced_state_black_list(self):
#         # Define which custom attributes will not be used when pickling
#         # the instance.
#         return ['_old_fields']
# 
#     def _complete_state(self):
#         # Reassign values for those attributes that were not pickled for
#         # being in the reduced_state_black_list.
#         self._refresh_old_fields()
# 
#     def _refresh_old_fields(self):
#         self._old_fields = {}
#         if self.id:
#             for field in self._vbm_meta.trackable_field_names:
#                 self._old_fields[field] = getattr(self, field)
# 
#     def __reduce__(self):
#         # Django doesn't call __getstate__ under certain circumstances (e.g.
#         # under the presence of deferred attributes), so we need to modify
#         # the current instance's __dict__ so that nothing extra gets pickled.
#         # It's the only thing that's going to work for sure.
#         full_dict = self.__dict__.copy()
#         for attr in self._reduced_state_black_list():
#             if attr in self.__dict__:
#                 del self.__dict__[attr]
#         result = super(Model, self).__reduce__()
#         self.__dict__ = full_dict
#         return result
# 
#     def __setstate__(self, state):
#         self.__dict__.update(state)
#         self._complete_state()
# 
#     class Meta:
#         abstract = True
# 
#     class VBMMeta:
#         '''
#         Default values for all custom meta options.
#         '''
#         trackable_field_names = ()


# Path: varnish_bans_manager/core/models/ban_submission.py
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import ugettext_lazy as _
from varnish_bans_manager.core.models import User
from varnish_bans_manager.core.models.base import Model

    )
    launched_at = models.DateTimeField(
        null=False
    )
    ban_type = models.PositiveSmallIntegerField(
        null=False,
        choices=BAN_TYPE_CHOICES
    )
    expression = models.CharField(
        max_length=2048,
        null=False
    )
    target_content_type = models.ForeignKey(ContentType)
    target_id = models.PositiveIntegerField()
    target = GenericForeignKey('target_content_type', 'target_id')
    created_at = models.DateTimeField(
        auto_now_add=True,
        null=False
    )
    updated_at = models.DateTimeField(
        auto_now=True,
        null=False
    )

    def _human_ban_type_name(self):
        return dict(self.BAN_TYPE_CHOICES)[self.ban_type]

    human_ban_type_name = property(_human_ban_type_name)



class BanSubmissionItem(Model):