Revision 09f54ceb
b/snf-astakos-app/astakos/im/management/commands/project-show.py | ||
---|---|---|
35 | 35 |
from django.core.management.base import BaseCommand, CommandError |
36 | 36 |
|
37 | 37 |
from synnefo.lib.ordereddict import OrderedDict |
38 |
from astakos.im.models import Chain |
|
38 |
from astakos.im.models import Chain, ProjectApplication
|
|
39 | 39 |
|
40 | 40 |
from ._common import format_bool, format_date |
41 | 41 |
|
... | ... | |
45 | 45 |
help = "Show project details" |
46 | 46 |
|
47 | 47 |
option_list = BaseCommand.option_list + ( |
48 |
make_option('--app', |
|
49 |
action='store_true', |
|
50 |
dest='app', |
|
51 |
default=False, |
|
52 |
help="Show application details instead"), |
|
48 | 53 |
make_option('--pending', |
49 | 54 |
action='store_true', |
50 | 55 |
dest='pending', |
... | ... | |
57 | 62 |
raise CommandError("Please provide project ID or name") |
58 | 63 |
|
59 | 64 |
show_pending = bool(options['pending']) |
65 |
search_apps = options['app'] |
|
60 | 66 |
|
61 | 67 |
name_or_id = args[0] |
62 | 68 |
is_id = name_or_id.isdigit() |
63 | 69 |
if is_id: |
64 | 70 |
name_or_id = int(name_or_id) |
65 | 71 |
|
66 |
chains = get_chains(name_or_id, is_id) |
|
67 |
infolist = collect_info(chains, show_pending) |
|
72 |
if search_apps: |
|
73 |
infolist = app_info(name_or_id, is_id) |
|
74 |
else: |
|
75 |
chains = get_chains(name_or_id, is_id) |
|
76 |
infolist = collect_info(chains, show_pending) |
|
68 | 77 |
|
69 |
# if not infolist:
|
|
70 |
# kind = 'project application' if search_application else 'project'
|
|
71 |
# field = 'id' if is_id else 'name'
|
|
72 |
# msg = "Unknown %s with %s '%s'" % (kind, field, name_or_id)
|
|
73 |
# raise CommandError(msg)
|
|
78 |
if not infolist: |
|
79 |
kind = 'project application' if search_apps else 'project'
|
|
80 |
field = 'id' if is_id else 'name' |
|
81 |
msg = "Unknown %s with %s '%s'" % (kind, field, name_or_id) |
|
82 |
raise CommandError(msg) |
|
74 | 83 |
|
75 | 84 |
for info in infolist: |
76 | 85 |
self.show_info(info) |
... | ... | |
82 | 91 |
self.stdout.write('\n') |
83 | 92 |
|
84 | 93 |
|
94 |
def app_info(name_or_id, is_id): |
|
95 |
try: |
|
96 |
apps = ([ProjectApplication.objects.get(id=name_or_id)] |
|
97 |
if is_id |
|
98 |
else ProjectApplication.objects.search_by_name(name_or_id)) |
|
99 |
return [app_fields(app) for app in apps] |
|
100 |
except ProjectApplication.DoesNotExist: |
|
101 |
return [] |
|
102 |
|
|
85 | 103 |
def get_chains(name_or_id, is_id): |
86 | 104 |
if is_id: |
87 | 105 |
try: |
Also available in: Unified diff