root / snf-astakos-app / astakos / im / management / commands / project-show.py @ e0a30018
History | View | Annotate | Download (6.4 kB)
1 |
# Copyright 2012-2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
from optparse import make_option |
35 |
from django.core.management.base import BaseCommand, CommandError |
36 |
|
37 |
from synnefo.lib.ordereddict import OrderedDict |
38 |
from astakos.im.models import Chain |
39 |
|
40 |
from ._common import format_bool, format_date |
41 |
|
42 |
|
43 |
class Command(BaseCommand): |
44 |
args = "<id or name>"
|
45 |
help = "Show project details"
|
46 |
|
47 |
option_list = BaseCommand.option_list + ( |
48 |
make_option('--pending',
|
49 |
action='store_true',
|
50 |
dest='pending',
|
51 |
default=False,
|
52 |
help="Show pending modification too"),
|
53 |
) |
54 |
|
55 |
def handle(self, *args, **options): |
56 |
if len(args) != 1: |
57 |
raise CommandError("Please provide project ID or name") |
58 |
|
59 |
show_pending = bool(options['pending']) |
60 |
|
61 |
name_or_id = args[0]
|
62 |
is_id = name_or_id.isdigit() |
63 |
if is_id:
|
64 |
name_or_id = int(name_or_id)
|
65 |
|
66 |
chains = get_chains(name_or_id, is_id) |
67 |
infolist = collect_info(chains, show_pending) |
68 |
|
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)
|
74 |
|
75 |
for info in infolist: |
76 |
self.show_info(info)
|
77 |
|
78 |
def show_info(self, info): |
79 |
for key, val in info.items(): |
80 |
line = '%s: %s\n' % (key.rjust(22), val) |
81 |
self.stdout.write(line)
|
82 |
self.stdout.write('\n') |
83 |
|
84 |
|
85 |
def get_chains(name_or_id, is_id): |
86 |
if is_id:
|
87 |
try:
|
88 |
return [Chain.objects.get(chain=name_or_id)]
|
89 |
except Chain.DoesNotExist:
|
90 |
return []
|
91 |
else:
|
92 |
return Chain.objects.search_by_name(name_or_id)
|
93 |
|
94 |
def collect_info(chains, pending): |
95 |
states = [chain.full_state() for chain in chains] |
96 |
|
97 |
infolist = [] |
98 |
for state in states: |
99 |
infolist += (chain_fields(state, pending)) |
100 |
return infolist
|
101 |
|
102 |
def chain_fields((s, project, app), request=False): |
103 |
l = [] |
104 |
if project:
|
105 |
l = [project_fields(s, project, app)] |
106 |
if request and s in Chain.PENDING_STATES: |
107 |
l.append(app_fields(app)) |
108 |
else:
|
109 |
l = [app_fields(app)] |
110 |
return l
|
111 |
|
112 |
def app_fields(app): |
113 |
mem_limit = app.limit_on_members_number |
114 |
mem_limit_show = mem_limit if mem_limit is not None else "unlimited" |
115 |
|
116 |
d = OrderedDict([ |
117 |
('project id', app.chain),
|
118 |
('application id', app.id),
|
119 |
('name', app.name),
|
120 |
('status', app.state_display()),
|
121 |
('owner', app.owner),
|
122 |
('homepage', app.homepage),
|
123 |
('description', app.description),
|
124 |
('comments for review', app.comments),
|
125 |
('request issue date', format_date(app.issue_date)),
|
126 |
('request start date', format_date(app.start_date)),
|
127 |
('request end date', format_date(app.end_date)),
|
128 |
('resources', app.resource_policies),
|
129 |
('join policy', app.member_join_policy_display),
|
130 |
('leave policy', app.member_leave_policy_display),
|
131 |
('max members', mem_limit_show),
|
132 |
]) |
133 |
|
134 |
return d
|
135 |
|
136 |
|
137 |
def project_fields(s, project, last_app): |
138 |
app = project.application |
139 |
|
140 |
d = OrderedDict([ |
141 |
('project id', project.id),
|
142 |
('application id', app.id),
|
143 |
('name', project.name),
|
144 |
('status', Chain.state_display(s)),
|
145 |
]) |
146 |
if s in Chain.PENDING_STATES: |
147 |
d.update([('pending application', last_app.id)])
|
148 |
|
149 |
d.update([('owner', app.owner),
|
150 |
('homepage', app.homepage),
|
151 |
('description', app.description),
|
152 |
('comments for review', app.comments),
|
153 |
('request issue date', format_date(app.issue_date)),
|
154 |
('request start date', format_date(app.start_date)),
|
155 |
('creation date', format_date(project.creation_date)),
|
156 |
('request end date', format_date(app.end_date)),
|
157 |
]) |
158 |
|
159 |
deact_date = project.deactivation_date |
160 |
if deact_date is not None: |
161 |
d['deactivation date'] = format_date(deact_date)
|
162 |
|
163 |
mem_limit = app.limit_on_members_number |
164 |
mem_limit_show = mem_limit if mem_limit is not None else "unlimited" |
165 |
|
166 |
d.update([ |
167 |
('resources', app.resource_policies),
|
168 |
('join policy', app.member_join_policy_display),
|
169 |
('leave policy', app.member_leave_policy_display),
|
170 |
('max members', mem_limit_show),
|
171 |
('total members', project.members_count()),
|
172 |
]) |
173 |
|
174 |
memberships = project.projectmembership_set |
175 |
accepted = [str(m.person) for m in memberships.any_accepted()] |
176 |
requested = [str(m.person) for m in memberships.requested()] |
177 |
suspended = [str(m.person) for m in memberships.suspended()] |
178 |
|
179 |
if accepted:
|
180 |
d['accepted members'] = ', '.join(accepted) |
181 |
|
182 |
if suspended:
|
183 |
d['suspended members'] = ', '.join(suspended) |
184 |
|
185 |
if requested:
|
186 |
d['membership requests'] = ', '.join(requested) |
187 |
|
188 |
return d
|