# 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 = ()
# 
# class JSONField(models.Field):
#     '''
#     Simple JSON field. See:
# 
#         - https://github.com/bradjasper/django-jsonfield
# 
#     '''
#     __metaclass__ = models.SubfieldBase
# 
#     def to_python(self, value):
#         if isinstance(value, basestring):
#             try:
#                 return json.loads(value)
#             except ValueError:
#                 pass
#         return value
# 
#     def get_prep_value(self, value):
#         if isinstance(value, basestring):
#             return value
#         if self.null and value is None:
#             return None
#         return json.dumps(value)
# 
#     def get_internal_type(self):
#         return 'TextField'


from django.db import models
from varnish_bans_manager.core.models.base import Model, JSONField

        def fset(cls, value):
            try:
                setting = cls.objects.get(name__iexact=name)
                setting.value = value
            except cls.DoesNotExist:
                setting = cls(name=name, value=value)
            setting.save()

        def fdel(cls):
            try:
                cls.objects.get(name__iexact=name).delete()
            except cls.DoesNotExist:
                pass

        return (fget, fset, fdel)

    host_matching_variable = property(*_property(
        'host_matching_variable',
        DEFAULT_HOST_MATCHING_VARIABLE))
    url_matching_variable = property(*_property(
        'url_matching_variable', DEFAULT_URL_MATCHING_VARIABLE))
    base_ban_expression = property(*_property(
        'base_ban_expression', ''))
    notify_bans = property(*_property(
        'notify_bans', False))
    notify_bans_task_status = property(*_property(
        'notify_bans_task_status', None))



# 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 = ()
# 
# class JSONField(models.Field):
#     '''
#     Simple JSON field. See:
# 
#         - https://github.com/bradjasper/django-jsonfield
# 
#     '''
#     __metaclass__ = models.SubfieldBase
# 
#     def to_python(self, value):
#         if isinstance(value, basestring):
#             try:
#                 return json.loads(value)
#             except ValueError:
#                 pass
#         return value
# 
#     def get_prep_value(self, value):
#         if isinstance(value, basestring):
#             return value
#         if self.null and value is None:
#             return None
#         return json.dumps(value)
# 
#     def get_internal_type(self):
#         return 'TextField'


# Path: varnish_bans_manager/core/models/setting.py
from django.db import models
from varnish_bans_manager.core.models.base import Model, JSONField


        def fset(cls, value):
            try:
                setting = cls.objects.get(name__iexact=name)
                setting.value = value
            except cls.DoesNotExist:
                setting = cls(name=name, value=value)
            setting.save()

        def fdel(cls):
            try:
                cls.objects.get(name__iexact=name).delete()
            except cls.DoesNotExist:
                pass

        return (fget, fset, fdel)

    host_matching_variable = property(*_property(
        'host_matching_variable',
        DEFAULT_HOST_MATCHING_VARIABLE))
    url_matching_variable = property(*_property(
        'url_matching_variable', DEFAULT_URL_MATCHING_VARIABLE))
    base_ban_expression = property(*_property(
        'base_ban_expression', ''))
    notify_bans = property(*_property(
        'notify_bans', False))
    notify_bans_task_status = property(*_property(
        'notify_bans_task_status', None))



class Setting(Model):