Revision 92359537 snf-astakos-app/astakos/im/management/commands/user-modify.py
b/snf-astakos-app/astakos/im/management/commands/user-modify.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from optparse import make_option |
35 |
from datetime import datetime |
|
36 | 35 |
|
37 | 36 |
from django.utils.translation import ugettext as _ |
38 | 37 |
from django.core.management.base import BaseCommand, CommandError |
... | ... | |
43 | 42 |
from astakos.im.functions import (activate, deactivate, |
44 | 43 |
set_pending_application_limit, |
45 | 44 |
unset_pending_application_limit) |
46 |
from ._common import remove_user_permission, add_user_permission |
|
45 |
from ._common import remove_user_permission, add_user_permission, is_uuid
|
|
47 | 46 |
|
48 | 47 |
|
49 | 48 |
class Command(BaseCommand): |
... | ... | |
123 | 122 |
raise CommandError("Please provide a user ID") |
124 | 123 |
|
125 | 124 |
if args[0].isdigit(): |
126 |
user_id = int(args[0]) |
|
127 |
user = AstakosUser.objects.get(id=user_id) |
|
125 |
try: |
|
126 |
user = AstakosUser.objects.get(id=int(args[0])) |
|
127 |
except AstakosUser.DoesNotExist: |
|
128 |
raise CommandError("Invalid user ID") |
|
129 |
elif is_uuid(args[0]): |
|
130 |
try: |
|
131 |
user = AstakosUser.objects.get(uuid=args[0]) |
|
132 |
except AstakosUser.DoesNotExist: |
|
133 |
raise CommandError("Invalid user UUID") |
|
128 | 134 |
else: |
129 |
raise CommandError("Invalid ID") |
|
130 |
|
|
131 |
if not user: |
|
132 |
raise CommandError("Unknown user") |
|
135 |
raise CommandError(("Invalid user identification: " |
|
136 |
"you should provide a valid user ID " |
|
137 |
"or a valid user UUID")) |
|
133 | 138 |
|
134 | 139 |
if options.get('admin'): |
135 | 140 |
user.is_superuser = True |
... | ... | |
226 | 231 |
m = _("Expected integer argument") |
227 | 232 |
raise CommandError(m) |
228 | 233 |
else: |
229 |
set_pending_application_limit(user_id, pending)
|
|
234 |
set_pending_application_limit(user.id, pending)
|
|
230 | 235 |
|
231 | 236 |
unset_pending = options.get('unset_pending') |
232 | 237 |
if unset_pending: |
233 |
unset_pending_application_limit(user_id) |
|
238 |
unset_pending_application_limit(user.id) |
Also available in: Unified diff