root / snf-astakos-app / astakos / im / management / commands / project-list.py @ c2a78208
History | View | Annotate | Download (5.5 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 snf_django.management.commands import ListCommand |
37 |
|
38 |
from astakos.im.models import Project, ProjectApplication |
39 |
from ._common import is_uuid |
40 |
|
41 |
|
42 |
class Command(ListCommand): |
43 |
help = """List projects and project status.
|
44 |
|
45 |
Project status can be one of:
|
46 |
Uninitialized an uninitialized project,
|
47 |
with no pending application
|
48 |
|
49 |
Pending an uninitialized project, pending review
|
50 |
|
51 |
Active an active project
|
52 |
|
53 |
Denied an uninitialized project, denied by the admin
|
54 |
|
55 |
Dismissed a denied project, dismissed by the applicant
|
56 |
|
57 |
Cancelled an uninitialized project, cancelled by the applicant
|
58 |
|
59 |
Suspended a project suspended by the admin;
|
60 |
it can later be resumed
|
61 |
|
62 |
Terminated a terminated project; its name can be claimed
|
63 |
by a new project
|
64 |
|
65 |
Deleted an uninitialized, deleted project"""
|
66 |
|
67 |
object_class = Project |
68 |
select_related = ["last_application", "owner"] |
69 |
|
70 |
option_list = ListCommand.option_list + ( |
71 |
make_option('--new',
|
72 |
action='store_true',
|
73 |
dest='new',
|
74 |
default=False,
|
75 |
help="List only new pending uninitialized projects"),
|
76 |
make_option('--modified',
|
77 |
action='store_true',
|
78 |
dest='modified',
|
79 |
default=False,
|
80 |
help="List only projects with pending modification"),
|
81 |
make_option('--pending',
|
82 |
action='store_true',
|
83 |
dest='pending',
|
84 |
default=False,
|
85 |
help=("Show only projects with a pending application "
|
86 |
"(equiv. --modified --new)")),
|
87 |
make_option('--deleted',
|
88 |
action='store_true',
|
89 |
dest='deleted',
|
90 |
default=False,
|
91 |
help="Also show cancelled/terminated projects"),
|
92 |
make_option('--base-projects',
|
93 |
action='store_true',
|
94 |
default=False,
|
95 |
help="Also show base projects"),
|
96 |
) |
97 |
|
98 |
def get_owner(project): |
99 |
return project.owner.email if project.owner else None |
100 |
|
101 |
def get_status(project): |
102 |
return project.state_display()
|
103 |
|
104 |
def get_pending_app(project): |
105 |
app = project.last_application |
106 |
return app.id if app and app.state == app.PENDING else "" |
107 |
|
108 |
FIELDS = { |
109 |
"id": ("uuid", "Project ID"), |
110 |
"name": ("realname", "Project Name"), |
111 |
"owner": (get_owner, "Project Owner"), |
112 |
"status": (get_status, "Project Status"), |
113 |
"pending_app": (get_pending_app,
|
114 |
"An application pending for the project"),
|
115 |
} |
116 |
|
117 |
fields = ["id", "name", "owner", "status", "pending_app"] |
118 |
|
119 |
def handle_args(self, *args, **options): |
120 |
try:
|
121 |
name_filter = self.filters.pop("name") |
122 |
self.filters["realname"] = name_filter |
123 |
except KeyError: |
124 |
pass
|
125 |
|
126 |
try:
|
127 |
owner_filter = self.filters.pop("owner") |
128 |
if owner_filter is not None: |
129 |
if is_uuid(owner_filter):
|
130 |
self.filters["owner__uuid"] = owner_filter |
131 |
else:
|
132 |
self.filters["owner__email"] = owner_filter |
133 |
except KeyError: |
134 |
pass
|
135 |
|
136 |
if not options['deleted']: |
137 |
self.excludes["state__in"] = Project.SKIP_STATES |
138 |
|
139 |
if not options['base_projects']: |
140 |
self.excludes["is_base"] = True |
141 |
|
142 |
if options["pending"]: |
143 |
self.filter_pending()
|
144 |
else:
|
145 |
if options['new']: |
146 |
self.filter_pending()
|
147 |
self.filters["state"] = Project.UNINITIALIZED |
148 |
if options['modified']: |
149 |
self.filter_pending()
|
150 |
self.filters["state__in"] = Project.INITIALIZED_STATES |
151 |
|
152 |
def filter_pending(self): |
153 |
self.filters["last_application__state"] = ProjectApplication.PENDING |