Revision f557d10a snf-astakos-app/astakos/im/management/commands/project-list.py
b/snf-astakos-app/astakos/im/management/commands/project-list.py | ||
---|---|---|
70 | 70 |
""" |
71 | 71 |
|
72 | 72 |
option_list = NoArgsCommand.option_list + ( |
73 |
make_option('-c',
|
|
73 |
make_option('--all',
|
|
74 | 74 |
action='store_true', |
75 |
dest='csv',
|
|
75 |
dest='all',
|
|
76 | 76 |
default=False, |
77 |
help="Use pipes to separate values"), |
|
77 |
help="List all projects (default)"), |
|
78 |
make_option('--new', |
|
79 |
action='store_true', |
|
80 |
dest='new', |
|
81 |
default=False, |
|
82 |
help="List only new project requests"), |
|
83 |
make_option('--modified', |
|
84 |
action='store_true', |
|
85 |
dest='modified', |
|
86 |
default=False, |
|
87 |
help="List only projects with pending modification"), |
|
88 |
make_option('--pending', |
|
89 |
action='store_true', |
|
90 |
dest='pending', |
|
91 |
default=False, |
|
92 |
help=("Show only projects with a pending application " |
|
93 |
"(equiv. --modified --new)")), |
|
78 | 94 |
make_option('--skip', |
79 | 95 |
action='store_true', |
80 | 96 |
dest='skip', |
... | ... | |
85 | 101 |
dest='full', |
86 | 102 |
default=False, |
87 | 103 |
help="Do not shorten long names"), |
88 |
make_option('--pending',
|
|
104 |
make_option('-c',
|
|
89 | 105 |
action='store_true', |
90 |
dest='pending',
|
|
106 |
dest='csv',
|
|
91 | 107 |
default=False, |
92 |
help="Show only projects with a pending application"),
|
|
93 |
) |
|
108 |
help="Use pipes to separate values"),
|
|
109 |
)
|
|
94 | 110 |
|
95 | 111 |
def handle_noargs(self, **options): |
112 |
allow_shorten = not options['full'] |
|
113 |
csv = options['csv'] |
|
114 |
|
|
115 |
chain_dict = Chain.objects.all_full_state() |
|
116 |
|
|
117 |
if not options['all']: |
|
118 |
f_states = [] |
|
119 |
if options['new']: |
|
120 |
f_states.append(Chain.PENDING) |
|
121 |
if options['modified']: |
|
122 |
f_states += Chain.MODIFICATION_STATES |
|
123 |
if options['pending']: |
|
124 |
f_states.append(Chain.PENDING) |
|
125 |
f_states += Chain.MODIFICATION_STATES |
|
126 |
if options['skip']: |
|
127 |
if not f_states: |
|
128 |
f_states = Chain.RELEVANT_STATES |
|
129 |
|
|
130 |
if f_states: |
|
131 |
chain_dict = filter_by_state(chain_dict, f_states) |
|
132 |
|
|
133 |
self.show(csv, allow_shorten, chain_dict) |
|
134 |
|
|
135 |
def show(self, csv, allow_shorten, chain_dict): |
|
96 | 136 |
labels = ('ProjID', 'Name', 'Applicant', 'Email', 'Status', 'AppID') |
97 | 137 |
columns = (7, 23, 20, 20, 17, 7) |
98 | 138 |
|
99 |
if not options['csv']:
|
|
139 |
if not csv:
|
|
100 | 140 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
101 | 141 |
self.stdout.write(line + '\n') |
102 | 142 |
sep = '-' * len(line) |
103 | 143 |
self.stdout.write(sep + '\n') |
104 | 144 |
|
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 | 145 |
for info in chain_info(chain_dict): |
115 | 146 |
|
116 | 147 |
fields = [ |
... | ... | |
124 | 155 |
|
125 | 156 |
fields = [(format(elem), flag) for (elem, flag) in fields] |
126 | 157 |
|
127 |
if options['csv']:
|
|
158 |
if csv:
|
|
128 | 159 |
line = '|'.join(fields) |
129 | 160 |
else: |
130 | 161 |
output = [] |
... | ... | |
138 | 169 |
|
139 | 170 |
self.stdout.write(line + '\n') |
140 | 171 |
|
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): |
|
172 |
def filter_by_state(chain_dict, states): |
|
149 | 173 |
d = {} |
150 | 174 |
for chain, (state, project, app) in chain_dict.iteritems(): |
151 |
if state not in Chain.SKIP_STATES:
|
|
175 |
if state in states:
|
|
152 | 176 |
d[chain] = (state, project, app) |
153 | 177 |
return d |
154 | 178 |
|
Also available in: Unified diff