# Path: varnish_bans_manager/core/models/cache.py
# class Group(Cache):
#     name = models.CharField(
#         _('Name'),
#         help_text=_(
#             'Some name used internally by VBM to refer to the group of '
#             'caching nodes.'),
#         max_length=255,
#         null=False
#     )
#     weight = models.SmallIntegerField(
#         default=0,
#         null=False
#     )
#     revision = RevisionField()
#     created_at = models.DateTimeField(
#         auto_now_add=True,
#         null=False
#     )
#     updated_at = models.DateTimeField(
#         auto_now=True,
#         null=False
#     )
# 
#     # Cache methods.
#     def _human_name(self):
#         return self.name
# 
#     human_name = property(_human_name)
# 
#     def _items(self):
#         return self.nodes.all().order_by('weight', 'created_at')
# 
#     items = property(_items)
# 
#     class Meta:
#         verbose_name = _('cache group')
#         verbose_name_plural = _('cache groups')


from optparse import make_option
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand, CommandError
from varnish_bans_manager.core.models import Group
    help = '''Usage,

    groups --list
    groups --add --name <value>
    groups --delete --id <value>
    '''

    def handle(self, *args, **options):
        # --list
        if options.get('op') == 'list':
            return self._list()

        # --add
        elif options.get('op') == 'add' and \
             options.get('name') is not None:
            return self._add(
                options.get('name'),
            )

        # --delete
        elif options.get('op') == 'delete' and \
             options.get('id') is not None:
            return self._delete(
                self._get_object_or_command_error(Group, options.get('id'))
            )

        raise CommandError(self.help)

    def _list(self):
        self.stdout.write('id, name\n')

# Path: varnish_bans_manager/core/models/cache.py
# class Group(Cache):
#     name = models.CharField(
#         _('Name'),
#         help_text=_(
#             'Some name used internally by VBM to refer to the group of '
#             'caching nodes.'),
#         max_length=255,
#         null=False
#     )
#     weight = models.SmallIntegerField(
#         default=0,
#         null=False
#     )
#     revision = RevisionField()
#     created_at = models.DateTimeField(
#         auto_now_add=True,
#         null=False
#     )
#     updated_at = models.DateTimeField(
#         auto_now=True,
#         null=False
#     )
# 
#     # Cache methods.
#     def _human_name(self):
#         return self.name
# 
#     human_name = property(_human_name)
# 
#     def _items(self):
#         return self.nodes.all().order_by('weight', 'created_at')
# 
#     items = property(_items)
# 
#     class Meta:
#         verbose_name = _('cache group')
#         verbose_name_plural = _('cache groups')


# Path: varnish_bans_manager/core/management/commands/groups.py
from optparse import make_option
from django.core.exceptions import ValidationError
from django.core.management.base import BaseCommand, CommandError
from varnish_bans_manager.core.models import Group

    help = '''Usage,

    groups --list
    groups --add --name <value>
    groups --delete --id <value>
    '''

    def handle(self, *args, **options):
        # --list
        if options.get('op') == 'list':
            return self._list()

        # --add
        elif options.get('op') == 'add' and \
             options.get('name') is not None:
            return self._add(
                options.get('name'),
            )

        # --delete
        elif options.get('op') == 'delete' and \
             options.get('id') is not None:
            return self._delete(
                self._get_object_or_command_error(Group, options.get('id'))
            )

        raise CommandError(self.help)

    def _list(self):
        self.stdout.write('id, name\n')

        for group in Group.objects.order_by('weight', 'created_at').all():