summaryrefslogtreecommitdiff
path: root/program/management/commands/deleteuser.py
blob: db2cb60b6e5f79654c2f9a894d3cb91ba4e3bce1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError

from optparse import make_option


class Command(BaseCommand):
    help = 'deletes an user'
    option_list = BaseCommand.option_list + (
        make_option('--username', dest='username', default=None, help='Specifies the username.'),
    )

    def handle(self, *args, **options):
        username = options.get('username', None)

        if not username:
            raise CommandError("You must use --username.")
        try:
            User.objects.get(username=username).delete()
        except User.DoesNotExist:
            raise 'user does not exist.'
        else:
            print 'user deleted succesfuly.'