1 from django.core.management.base import LabelCommand, CommandError |
1 from django.core.management.base import LabelCommand, CommandError, BaseCommand, make_option |
|
2 from base64 import b64decode |
2 |
3 |
3 class Command(LabelCommand): |
4 class Command(LabelCommand): |
|
5 option_list = BaseCommand.option_list + ( |
|
6 make_option('--base64', action='store_true', dest='base64', default=False, |
|
7 help='Assume all input are base64 encoded.'), |
|
8 ) |
|
9 |
4 help = "Create manager" |
10 help = "Create manager" |
5 |
11 |
6 def handle(self, *labels, **options): |
12 def handle(self, *labels, **options): |
7 if len(labels)!=5: |
13 if len(labels)!=5: |
8 raise CommandError("Enter manager's email, username, password, first_name, last_name") |
14 raise CommandError("Enter manager's email, username, password, first_name, last_name") |
9 email = labels[0] |
15 |
10 username = labels[1] |
16 base64 = options.get('base64') |
11 password = labels[2] |
17 if base64: |
12 first_name = labels[3] |
18 email = b64decode(labels[0]) |
13 last_name = labels[4] |
19 username = b64decode(labels[1]) |
|
20 password = b64decode(labels[2]) |
|
21 first_name = b64decode(labels[3]) |
|
22 last_name = b64decode(labels[4]) |
|
23 else: |
|
24 email = labels[0] |
|
25 username = labels[1] |
|
26 password = labels[2] |
|
27 first_name = labels[3] |
|
28 last_name = labels[4] |
|
29 |
|
30 email = email.decode('utf8') |
|
31 username = username.decode('utf8') |
|
32 password = password.decode('utf8') |
|
33 first_name = first_name.decode('utf8') |
|
34 last_name = last_name.decode('utf8') |
14 |
35 |
15 from cm.models import UserProfile |
36 from cm.models import UserProfile |
16 UserProfile.objects._create_manager(email, username, password, first_name, last_name) |
37 UserProfile.objects._create_manager(email, username, password, first_name, last_name) |