Revision 04e05445
b/snf-astakos-app/astakos/im/management/commands/user-add.py | ||
---|---|---|
41 | 41 |
|
42 | 42 |
from astakos.im.models import AstakosUser |
43 | 43 |
from astakos.im.api.callpoint import AstakosCallpoint |
44 |
from astakos.im.functions import activate |
|
44 | 45 |
|
45 | 46 |
def filter_custom_options(options): |
46 | 47 |
base_dests = list( |
... | ... | |
63 | 64 |
help="Set user's password"), |
64 | 65 |
make_option('--active', |
65 | 66 |
action='store_true', |
66 |
dest='is_active',
|
|
67 |
dest='active', |
|
67 | 68 |
default=False, |
68 |
help="Activate user"),
|
|
69 |
help="Set active"),
|
|
69 | 70 |
make_option('--admin', |
70 | 71 |
action='store_true', |
71 | 72 |
dest='is_superuser', |
... | ... | |
86 | 87 |
raise CommandError("Invalid number of arguments") |
87 | 88 |
|
88 | 89 |
email, first_name, last_name = (args[i].decode('utf8') for i in range(3)) |
89 |
|
|
90 |
|
|
90 | 91 |
try: |
91 | 92 |
validate_email(email) |
92 | 93 |
except ValidationError: |
... | ... | |
97 | 98 |
'last_name':last_name |
98 | 99 |
} |
99 | 100 |
u.update(filter_custom_options(options)) |
101 |
u.pop('active') |
|
100 | 102 |
if not u.get('password'): |
101 | 103 |
u['password'] = AstakosUser.objects.make_random_password() |
102 | 104 |
|
103 | 105 |
try: |
104 | 106 |
c = AstakosCallpoint() |
105 | 107 |
r = c.create_users((u,)).next() |
106 |
except socket.error, e: |
|
107 |
raise CommandError(e) |
|
108 |
except ValidationError, e: |
|
108 |
except BaseException, e: |
|
109 | 109 |
raise CommandError(e) |
110 | 110 |
else: |
111 | 111 |
if not r.is_success: |
112 | 112 |
raise CommandError(r.reason) |
113 | 113 |
else: |
114 |
if options['active']: |
|
115 |
user_id = r.data.get('id') |
|
116 |
user = AstakosUser.objects.get(id = user_id) |
|
117 |
activate(user) |
|
114 | 118 |
self.stdout.write('User created successfully ') |
115 | 119 |
if not options.get('password'): |
116 | 120 |
self.stdout.write('with password: %s\n' % u['password']) |
117 | 121 |
else: |
118 |
self.stdout.write('\n') |
|
122 |
self.stdout.write('\n') |
Also available in: Unified diff