root / snf-astakos-app / astakos / im / management / commands / project-show.py @ cb6b8c79
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 |
from django.core.management.base import BaseCommand, CommandError |
36 |
|
37 |
from synnefo.lib.ordereddict import OrderedDict |
38 |
from astakos.im.models import ProjectApplication, Project |
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('--app',
|
49 |
action='store_true',
|
50 |
dest='app',
|
51 |
default=False,
|
52 |
help="Show application details instead"),
|
53 |
) |
54 |
|
55 |
def handle(self, *args, **options): |
56 |
if len(args) != 1: |
57 |
raise CommandError("Please provide ID or name") |
58 |
|
59 |
name_or_id = args[0]
|
60 |
is_id = name_or_id.isdigit() |
61 |
if is_id:
|
62 |
name_or_id = int(name_or_id)
|
63 |
|
64 |
infolist = (app_info(name_or_id, is_id) if options['app'] |
65 |
else project_info(name_or_id, is_id))
|
66 |
|
67 |
for info in infolist: |
68 |
self.show_info(info)
|
69 |
|
70 |
def show_info(self, info): |
71 |
for key, val in info.items(): |
72 |
line = '%s: %s\n' % (key.rjust(22), val) |
73 |
self.stdout.write(line.encode('utf8')) |
74 |
self.stdout.write('\n') |
75 |
|
76 |
|
77 |
def app_fields(app): |
78 |
d = OrderedDict([ |
79 |
('application id', app.id),
|
80 |
('project id', app.chain),
|
81 |
('name', app.name),
|
82 |
('owner', app.owner),
|
83 |
('status', app.state_display()),
|
84 |
('homepage', app.homepage),
|
85 |
('description', app.description),
|
86 |
('issue date', format_date(app.issue_date)),
|
87 |
('start date', format_date(app.start_date)),
|
88 |
('end date', format_date(app.end_date)),
|
89 |
('comments', app.comments),
|
90 |
('resources', app.resource_policies),
|
91 |
('join policy', app.member_join_policy_display),
|
92 |
('leave policy', app.member_leave_policy_display),
|
93 |
('max members', app.limit_on_members_number),
|
94 |
]) |
95 |
|
96 |
return d
|
97 |
|
98 |
|
99 |
def project_fields(project): |
100 |
app = project.application |
101 |
d = OrderedDict([ |
102 |
('project id', project.id),
|
103 |
('application id', app.id),
|
104 |
('name', project.name),
|
105 |
('owner', app.owner),
|
106 |
('status', project.state_display()),
|
107 |
('creation date', format_date(project.creation_date)),
|
108 |
]) |
109 |
deact_date = project.deactivation_date |
110 |
if deact_date is not None: |
111 |
d['deactivation date'] = format_date(deact_date)
|
112 |
|
113 |
d.update([ |
114 |
('homepage', app.homepage),
|
115 |
('description', app.description),
|
116 |
('resources', app.resource_policies),
|
117 |
('join policy', app.member_join_policy_display),
|
118 |
('leave policy', app.member_leave_policy_display),
|
119 |
('max members', app.limit_on_members_number),
|
120 |
('total members', project.members_count()),
|
121 |
]) |
122 |
|
123 |
memberships = project.projectmembership_set |
124 |
accepted = [str(m.person) for m in memberships.any_accepted()] |
125 |
requested = [str(m.person) for m in memberships.requested()] |
126 |
suspended = [str(m.person) for m in memberships.suspended()] |
127 |
|
128 |
if accepted:
|
129 |
d['accepted members'] = ', '.join(accepted) |
130 |
|
131 |
if suspended:
|
132 |
d['suspended members'] = ', '.join(suspended) |
133 |
|
134 |
if requested:
|
135 |
d['membership requests'] = ', '.join(requested) |
136 |
|
137 |
return d
|
138 |
|
139 |
|
140 |
def app_info(name_or_id, is_id): |
141 |
try:
|
142 |
apps = ([ProjectApplication.objects.get(id=name_or_id)] |
143 |
if is_id
|
144 |
else ProjectApplication.objects.search_by_name(name_or_id))
|
145 |
return [app_fields(app) for app in apps] |
146 |
except ProjectApplication.DoesNotExist:
|
147 |
return []
|
148 |
|
149 |
|
150 |
def project_info(name_or_id, is_id): |
151 |
try:
|
152 |
projects = ([Project.objects.get(id=name_or_id)] |
153 |
if is_id
|
154 |
else Project.objects.search_by_name(name_or_id))
|
155 |
return [project_fields(project) for project in projects] |
156 |
except Project.DoesNotExist:
|
157 |
return []
|