root / snf-astakos-app / astakos / im / management / commands / project-list.py @ b6eaca30
History | View | Annotate | Download (5.9 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 |
|
36 |
from django.core.management.base import NoArgsCommand |
37 |
|
38 |
from astakos.im.models import Chain |
39 |
from ._common import format, shortened |
40 |
|
41 |
|
42 |
class Command(NoArgsCommand): |
43 |
help = """
|
44 |
List projects and project status.
|
45 |
|
46 |
Project status can be one of:
|
47 |
Pending an application <AppId> for a new project
|
48 |
|
49 |
Active an active project
|
50 |
|
51 |
Active - Pending an active project with
|
52 |
a pending modification <AppId>
|
53 |
|
54 |
Denied an application for a new project,
|
55 |
denied by the admin
|
56 |
|
57 |
Dismissed a denied project, dismissed by the applicant
|
58 |
|
59 |
Cancelled an application for a new project,
|
60 |
cancelled by the applicant
|
61 |
|
62 |
Suspended a project suspended by the admin;
|
63 |
it can later be resumed
|
64 |
|
65 |
Suspended - Pending a suspended project with
|
66 |
a pending modification <AppId>
|
67 |
|
68 |
Terminated a terminated project; its name can be claimed
|
69 |
by a new project
|
70 |
"""
|
71 |
|
72 |
option_list = NoArgsCommand.option_list + ( |
73 |
make_option('-c',
|
74 |
action='store_true',
|
75 |
dest='csv',
|
76 |
default=False,
|
77 |
help="Use pipes to separate values"),
|
78 |
make_option('--skip',
|
79 |
action='store_true',
|
80 |
dest='skip',
|
81 |
default=False,
|
82 |
help="Skip cancelled and terminated projects"),
|
83 |
make_option('--full',
|
84 |
action='store_true',
|
85 |
dest='full',
|
86 |
default=False,
|
87 |
help="Do not shorten long names"),
|
88 |
make_option('--pending',
|
89 |
action='store_true',
|
90 |
dest='pending',
|
91 |
default=False,
|
92 |
help="Show only projects with a pending application"),
|
93 |
) |
94 |
|
95 |
def handle_noargs(self, **options): |
96 |
labels = ('ProjID', 'Name', 'Applicant', 'Email', 'Status', 'AppID') |
97 |
columns = (7, 23, 20, 20, 17, 7) |
98 |
|
99 |
if not options['csv']: |
100 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
101 |
self.stdout.write(line + '\n') |
102 |
sep = '-' * len(line) |
103 |
self.stdout.write(sep + '\n') |
104 |
|
105 |
chain_dict = Chain.objects.all_full_state() |
106 |
if options['skip']: |
107 |
chain_dict = do_skip(chain_dict) |
108 |
|
109 |
if options['pending']: |
110 |
chain_dict = pending_only(chain_dict) |
111 |
|
112 |
allow_shorten = not options['full'] |
113 |
|
114 |
for info in chain_info(chain_dict): |
115 |
|
116 |
fields = [ |
117 |
(info['projectid'], False), |
118 |
(info['name'], True), |
119 |
(info['applicant'], True), |
120 |
(info['email'], True), |
121 |
(info['status'], False), |
122 |
(info['appid'], False), |
123 |
] |
124 |
|
125 |
fields = [(format(elem), flag) for (elem, flag) in fields] |
126 |
|
127 |
if options['csv']: |
128 |
line = '|'.join(fields)
|
129 |
else:
|
130 |
output = [] |
131 |
for (field, shorten), width in zip(fields, columns): |
132 |
s = (shortened(field, width) if shorten and allow_shorten |
133 |
else field)
|
134 |
s = s.rjust(width) |
135 |
output.append(s) |
136 |
|
137 |
line = ' '.join(output)
|
138 |
|
139 |
self.stdout.write(line + '\n') |
140 |
|
141 |
def pending_only(chain_dict): |
142 |
d = {} |
143 |
for chain, (state, project, app) in chain_dict.iteritems(): |
144 |
if state in Chain.PENDING_STATES: |
145 |
d[chain] = (state, project, app) |
146 |
return d
|
147 |
|
148 |
def do_skip(chain_dict): |
149 |
d = {} |
150 |
for chain, (state, project, app) in chain_dict.iteritems(): |
151 |
if state not in Chain.SKIP_STATES: |
152 |
d[chain] = (state, project, app) |
153 |
return d
|
154 |
|
155 |
def chain_info(chain_dict): |
156 |
l = [] |
157 |
for chain, (state, project, app) in chain_dict.iteritems(): |
158 |
status = Chain.state_display(state) |
159 |
if state in Chain.PENDING_STATES: |
160 |
appid = str(app.id)
|
161 |
else:
|
162 |
appid = ""
|
163 |
|
164 |
d = { |
165 |
'projectid' : str(chain), |
166 |
'name' : project.application.name if project else app.name, |
167 |
'applicant' : app.applicant.realname,
|
168 |
'email' : app.applicant.email,
|
169 |
'status': status,
|
170 |
'appid' : appid,
|
171 |
} |
172 |
l.append(d) |
173 |
return l
|