# 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')


from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from varnish_bans_manager.core.models import User
class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--add', dest='op', action='store_const', const='add'),
        make_option('--administrator', dest='administrator', default=False, action='store_const', const=True),
        make_option('--email', dest='email'),
        make_option('--password', dest='password'),
        make_option('--firstname', dest='firstname'),
        make_option('--lastname', dest='lastname'),
    )
    help = '''Usage,

    users --add [--administrator] --email <value> --password <value> --firstname <value> --lastname <value>
    '''

    def handle(self, *args, **options):
        # Check arguments.
        if options.get('op') != 'add' or \
           not options.get('email') or \
           not options.get('password') or \
           not options.get('firstname') or \
           not options.get('lastname'):
            raise CommandError(self.help)

        # Check duplicated e-mails.
        if User.objects.filter(email__iexact=options.get('email'), is_active=True).exists():
            raise CommandError(
                'There is already an user with that e-mail address.')

        # Choose user creation method (superuser vs normal user).
        create_user_method = getattr(

# 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/management/commands/users.py
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from varnish_bans_manager.core.models import User

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--add', dest='op', action='store_const', const='add'),
        make_option('--administrator', dest='administrator', default=False, action='store_const', const=True),
        make_option('--email', dest='email'),
        make_option('--password', dest='password'),
        make_option('--firstname', dest='firstname'),
        make_option('--lastname', dest='lastname'),
    )
    help = '''Usage,

    users --add [--administrator] --email <value> --password <value> --firstname <value> --lastname <value>
    '''

    def handle(self, *args, **options):
        # Check arguments.
        if options.get('op') != 'add' or \
           not options.get('email') or \
           not options.get('password') or \
           not options.get('firstname') or \
           not options.get('lastname'):
            raise CommandError(self.help)

        # Check duplicated e-mails.
        if User.objects.filter(email__iexact=options.get('email'), is_active=True).exists():
            raise CommandError(
                'There is already an user with that e-mail address.')

        # Choose user creation method (superuser vs normal user).
        create_user_method = getattr(

            User.objects,