root / snf-astakos-app / astakos / im / management / commands / project-list.py @ ffb5cca1
History | View | Annotate | Download (6 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 astakos.im.models import Chain, Project |
37 |
from synnefo.webproject.management.commands import ListCommand |
38 |
|
39 |
|
40 |
def get_name(chain): |
41 |
try:
|
42 |
p = Project.objects.get(pk=chain.pk) |
43 |
except Project.DoesNotExist:
|
44 |
app = chain.last_application() |
45 |
return app.name
|
46 |
else:
|
47 |
return p.name
|
48 |
|
49 |
|
50 |
def get_owner_name(chain): |
51 |
return chain.last_application().owner.realname
|
52 |
|
53 |
|
54 |
def get_owner_email(chain): |
55 |
return chain.last_application().owner.email
|
56 |
|
57 |
|
58 |
def get_state(chain): |
59 |
try:
|
60 |
p = Project.objects.get(pk=chain.pk) |
61 |
except Project.DoesNotExist:
|
62 |
p = None
|
63 |
app = chain.last_application() |
64 |
return chain.get_state(p, app)[0] |
65 |
|
66 |
|
67 |
def get_state_display(chain): |
68 |
return Chain.state_display(get_state(chain))
|
69 |
|
70 |
|
71 |
def get_appid(chain): |
72 |
try:
|
73 |
p = Project.objects.get(pk=chain.pk) |
74 |
except Project.DoesNotExist:
|
75 |
p = None
|
76 |
app = chain.last_application() |
77 |
state = chain.get_state(p, app)[0]
|
78 |
if state in Chain.PENDING_STATES: |
79 |
return str(app.id) |
80 |
else:
|
81 |
return "" |
82 |
|
83 |
|
84 |
class Command(ListCommand): |
85 |
help = """
|
86 |
List projects and project status.
|
87 |
|
88 |
Project status can be one of:
|
89 |
Pending an application <AppId> for a new project
|
90 |
|
91 |
Active an active project
|
92 |
|
93 |
Active - Pending an active project with
|
94 |
a pending modification <AppId>
|
95 |
|
96 |
Denied an application for a new project,
|
97 |
denied by the admin
|
98 |
|
99 |
Dismissed a denied project, dismissed by the applicant
|
100 |
|
101 |
Cancelled an application for a new project,
|
102 |
cancelled by the applicant
|
103 |
|
104 |
Suspended a project suspended by the admin;
|
105 |
it can later be resumed
|
106 |
|
107 |
Suspended - Pending a suspended project with
|
108 |
a pending modification <AppId>
|
109 |
|
110 |
Terminated a terminated project; its name can be claimed
|
111 |
by a new project
|
112 |
"""
|
113 |
|
114 |
object_class = Chain |
115 |
|
116 |
FIELDS = { |
117 |
'ProjID': ('pk', 'The id of the project'), |
118 |
'Name': (get_name, 'The name of the project'), |
119 |
'Owner': (get_owner_name, 'The name of the project owner'), |
120 |
'Email': (get_owner_email, 'The email of the project owner'), |
121 |
'Status': (get_state_display, 'The status of the project'), |
122 |
'AppID': (get_appid, 'The project application identification'), |
123 |
} |
124 |
|
125 |
fields = ['ProjID', 'Name', 'Owner', 'Email', 'Status', 'AppID'] |
126 |
|
127 |
option_list = ListCommand.option_list + ( |
128 |
make_option('--all',
|
129 |
action='store_true',
|
130 |
dest='all',
|
131 |
default=False,
|
132 |
help="List all projects (default)"),
|
133 |
make_option('--new',
|
134 |
action='store_true',
|
135 |
dest='new',
|
136 |
default=False,
|
137 |
help="List only new project applications"),
|
138 |
make_option('--modified',
|
139 |
action='store_true',
|
140 |
dest='modified',
|
141 |
default=False,
|
142 |
help="List only projects with pending modification"),
|
143 |
make_option('--pending',
|
144 |
action='store_true',
|
145 |
dest='pending',
|
146 |
default=False,
|
147 |
help=("Show only projects with a pending application "
|
148 |
"(equiv. --modified --new)")),
|
149 |
make_option('--skip',
|
150 |
action='store_true',
|
151 |
dest='skip',
|
152 |
default=False,
|
153 |
help="Skip cancelled and terminated projects"),
|
154 |
make_option('--full',
|
155 |
action='store_true',
|
156 |
dest='full',
|
157 |
default=False,
|
158 |
help="Do not shorten long names"),
|
159 |
) |
160 |
|
161 |
def handle_db_objects(self, objects, **options): |
162 |
if options['all']: |
163 |
return
|
164 |
|
165 |
f_states = [] |
166 |
if options['new']: |
167 |
f_states.append(Chain.PENDING) |
168 |
if options['modified']: |
169 |
f_states += Chain.MODIFICATION_STATES |
170 |
if options['pending']: |
171 |
f_states.append(Chain.PENDING) |
172 |
f_states += Chain.MODIFICATION_STATES |
173 |
if options['skip']: |
174 |
if not f_states: |
175 |
f_states = Chain.RELEVANT_STATES |
176 |
|
177 |
if f_states:
|
178 |
map(objects.remove,
|
179 |
filter(lambda o: get_state(o) not in f_states, objects)) |