Revision 44f510e1 snf-astakos-app/astakos/im/management/commands/user-modify.py
b/snf-astakos-app/astakos/im/management/commands/user-modify.py | ||
---|---|---|
39 | 39 |
from django.contrib.auth.models import Group |
40 | 40 |
from django.core.exceptions import ValidationError |
41 | 41 |
|
42 |
from synnefo.util import units |
|
42 | 43 |
from astakos.im.models import AstakosUser, Resource |
43 | 44 |
from astakos.im import quotas |
44 | 45 |
from astakos.im import activation_backends |
45 |
from ._common import remove_user_permission, add_user_permission, is_uuid |
|
46 |
from ._common import (remove_user_permission, add_user_permission, is_uuid, |
|
47 |
show_resource_value) |
|
46 | 48 |
from snf_django.lib.db.transaction import commit_on_success_strict |
47 | 49 |
|
48 | 50 |
activation_backend = activation_backends.get_backend() |
... | ... | |
290 | 292 |
self.set_limit(user, resource, capacity, False) |
291 | 293 |
|
292 | 294 |
def set_limit(self, user, resource, capacity, force): |
295 |
style = None |
|
293 | 296 |
if capacity != 'default': |
294 | 297 |
try: |
295 |
capacity = int(capacity)
|
|
296 |
except ValueError:
|
|
298 |
capacity, style = units.parse_with_style(capacity)
|
|
299 |
except: |
|
297 | 300 |
m = "Please specify capacity as a decimal integer or 'default'" |
298 | 301 |
raise CommandError(m) |
299 | 302 |
|
... | ... | |
302 | 305 |
except Resource.DoesNotExist: |
303 | 306 |
raise CommandError("No such resource: %s" % resource) |
304 | 307 |
|
305 |
current = quota.capacity if quota is not None else 'default' |
|
306 |
|
|
307 | 308 |
if not force: |
309 |
s_default = show_resource_value(default_capacity, resource, style) |
|
310 |
s_current = (show_resource_value(quota.capacity, resource, style) |
|
311 |
if quota is not None else 'default') |
|
312 |
s_capacity = (show_resource_value(capacity, resource, style) |
|
313 |
if capacity != 'default' else capacity) |
|
308 | 314 |
self.stdout.write("user: %s (%s)\n" % (user.uuid, user.username)) |
309 |
self.stdout.write("default capacity: %s\n" % default_capacity)
|
|
310 |
self.stdout.write("current capacity: %s\n" % current) |
|
311 |
self.stdout.write("new capacity: %s\n" % capacity) |
|
315 |
self.stdout.write("default capacity: %s\n" % s_default)
|
|
316 |
self.stdout.write("current capacity: %s\n" % s_current)
|
|
317 |
self.stdout.write("new capacity: %s\n" % s_capacity)
|
|
312 | 318 |
self.stdout.write("Confirm? (y/n) ") |
313 | 319 |
response = raw_input() |
314 | 320 |
if string.lower(response) not in ['y', 'yes']: |
Also available in: Unified diff