0001-misc-display-after-job-progression-46672.patch
tests/api/test_all.py | ||
---|---|---|
246 | 246 |
'status': 'registered', |
247 | 247 |
'creation_time': job.creation_time, |
248 | 248 |
'completion_time': None, |
249 |
'completion_status': None,
|
|
249 |
'completion_status': '',
|
|
250 | 250 |
}, |
251 | 251 |
} |
tests/backoffice_pages/test_export.py | ||
---|---|---|
221 | 221 | |
222 | 222 |
# check afterjob ajax call |
223 | 223 |
status_resp = app.get('/afterjobs/' + job_id) |
224 |
assert status_resp.text == 'completed|completed' |
|
224 |
assert status_resp.text == 'completed|completed 2/2 (100%)'
|
|
225 | 225 | |
226 | 226 |
# check error handling |
227 | 227 |
app.get('/afterjobs/whatever', status=404) |
wcs/admin/settings.py | ||
---|---|---|
1037 | 1037 |
if f in ('.indexes', '.max_id'): |
1038 | 1038 |
continue |
1039 | 1039 |
z.write(os.path.join(path, f), os.path.join(d, f)) |
1040 |
job.increment_count() |
|
1040 | 1041 |
if 'datasources' in self.dirs: |
1041 | 1042 |
for ds in NamedDataSource.select(): |
1042 | 1043 |
if ds.external == 'agenda': |
... | ... | |
1047 | 1048 |
os.path.join('datasources', str(ds.id)), |
1048 | 1049 |
ET.tostring(node), |
1049 | 1050 |
) |
1051 |
job.increment_count() |
|
1050 | 1052 |
if 'formdefs' in self.dirs: |
1051 | 1053 |
for formdef in FormDef.select(): |
1052 | 1054 |
node = formdef.export_to_xml(include_id=True) |
... | ... | |
1055 | 1057 |
os.path.join('formdefs_xml', str(formdef.id)), |
1056 | 1058 |
b'<?xml version="1.0"?>\n' + ET.tostring(node), |
1057 | 1059 |
) |
1060 |
job.increment_count() |
|
1058 | 1061 |
if 'carddefs' in self.dirs: |
1059 | 1062 |
for formdef in CardDef.select(): |
1060 | 1063 |
node = formdef.export_to_xml(include_id=True) |
... | ... | |
1063 | 1066 |
os.path.join('carddefs_xml', str(formdef.id)), |
1064 | 1067 |
b'<?xml version="1.0"?>\n' + ET.tostring(node), |
1065 | 1068 |
) |
1069 |
job.increment_count() |
|
1066 | 1070 |
if 'workflows' in self.dirs: |
1067 | 1071 |
for workflow in Workflow.select(): |
1068 | 1072 |
node = workflow.export_to_xml(include_id=True) |
... | ... | |
1071 | 1075 |
os.path.join('workflows_xml', str(workflow.id)), |
1072 | 1076 |
b'<?xml version="1.0"?>\n' + ET.tostring(node), |
1073 | 1077 |
) |
1078 |
job.increment_count() |
|
1074 | 1079 |
if 'blockdefs' in self.dirs: |
1075 | 1080 |
for blockdef in BlockDef.select(): |
1076 | 1081 |
node = blockdef.export_to_xml(include_id=True) |
... | ... | |
1079 | 1084 |
os.path.join('blockdefs_xml', str(blockdef.id)), |
1080 | 1085 |
b'<?xml version="1.0"?>\n' + ET.tostring(node), |
1081 | 1086 |
) |
1087 |
job.increment_count() |
|
1082 | 1088 |
if 'roles' in self.dirs: |
1083 | 1089 |
for role in get_publisher().role_class.select(): |
1084 | 1090 |
node = role.export_to_xml(include_id=True) |
... | ... | |
1087 | 1093 |
os.path.join('roles_xml', str(role.id)), |
1088 | 1094 |
b'<?xml version="1.0"?>\n' + ET.tostring(node), |
1089 | 1095 |
) |
1096 |
job.increment_count() |
|
1090 | 1097 | |
1091 | 1098 |
if self.settings: |
1092 | 1099 |
z.write(os.path.join(self.app_dir, 'config.pck'), 'config.pck') |
1100 |
job.increment_count() |
|
1093 | 1101 |
for f in os.listdir(self.app_dir): |
1094 | 1102 |
if f.startswith('idp-') and os.path.splitext(f)[-1] in ('.pem', '.xml'): |
1095 | 1103 |
z.write(os.path.join(self.app_dir, f), f) |
1104 |
job.increment_count() |
|
1096 | 1105 |
if os.path.exists(os.path.join(self.app_dir, 'config')): |
1097 | 1106 |
for f in os.listdir(os.path.join(self.app_dir, 'config')): |
1098 | 1107 |
z.write(os.path.join(self.app_dir, 'config', f), os.path.join('config', f)) |
1108 |
job.increment_count() |
|
1099 | 1109 | |
1110 |
job.total_count = job.current_count |
|
1100 | 1111 |
job.file_content = c.getvalue() |
1101 | 1112 |
job.store() |
1102 | 1113 |
wcs/api.py | ||
---|---|---|
1172 | 1172 |
'label': self.afterjob.label, |
1173 | 1173 |
'creation_time': self.afterjob.creation_time, |
1174 | 1174 |
'completion_time': self.afterjob.completion_time, |
1175 |
'completion_status': self.afterjob.completion_status,
|
|
1175 |
'completion_status': self.afterjob.get_completion_status(),
|
|
1176 | 1176 |
}, |
1177 | 1177 |
}, |
1178 | 1178 |
cls=misc.JSONEncoder, |
wcs/backoffice/data_management.py | ||
---|---|---|
363 | 363 |
def execute(self): |
364 | 364 |
self.carddef = self.kwargs['carddef_class'].get(self.kwargs['carddef_id']) |
365 | 365 |
carddata_class = self.carddef.data_class() |
366 |
for item in self.kwargs['data_lines']: |
|
366 |
self.total_count = len(self.kwargs['data_lines']) |
|
367 |
self.store() |
|
368 | ||
369 |
for i, item in enumerate(self.kwargs['data_lines']): |
|
367 | 370 |
data_instance = carddata_class() |
368 | 371 |
user_value = item.pop('_user', None) |
369 | 372 |
data_instance.user = self.user_lookup(user_value) |
... | ... | |
371 | 374 |
data_instance.just_created() |
372 | 375 |
data_instance.store() |
373 | 376 |
data_instance.perform_workflow(event='csv-import-created') |
377 |
self.increment_count() |
|
374 | 378 | |
375 | 379 |
def done_action_url(self): |
376 | 380 |
carddef = self.kwargs['carddef_class'].get(self.kwargs['carddef_id']) |
wcs/backoffice/management.py | ||
---|---|---|
3894 | 3894 |
return |
3895 | 3895 | |
3896 | 3896 |
formdatas = formdef.data_class().get_ids(item_ids, order_by='receipt_time') |
3897 |
self.completion_status = f'0/{len(formdatas)}'
|
|
3897 |
self.total_count = len(formdatas)
|
|
3898 | 3898 |
self.store() |
3899 | 3899 | |
3900 | 3900 |
publisher = get_publisher() |
... | ... | |
3910 | 3910 |
{ |
3911 | 3911 |
'oldest_form': oldest_lazy_form, |
3912 | 3912 |
'mass_action_index': i, |
3913 |
'mass_action_length': len(formdatas),
|
|
3913 |
'mass_action_length': self.total_count,
|
|
3914 | 3914 |
} |
3915 | 3915 |
) |
3916 | 3916 |
if getattr(action['action'], 'status_action', False): |
... | ... | |
3921 | 3921 |
else: |
3922 | 3922 |
# global action |
3923 | 3923 |
formdata.perform_global_action(action['action'].id, user) |
3924 |
self.completion_status = f'{i + 1}/{len(formdatas)}' |
|
3925 |
self.store() |
|
3924 |
self.increment_count() |
|
3926 | 3925 | |
3927 | 3926 |
def done_action_url(self): |
3928 | 3927 |
return self.kwargs['return_url'] |
... | ... | |
3970 | 3969 |
items, total_count = FormDefUI(formdef).get_listing_items( |
3971 | 3970 |
fields, selected_filter, user=user, query=query, criterias=criterias, order_by=order_by |
3972 | 3971 |
) |
3972 |
self.total_count = total_count |
|
3973 |
self.store() |
|
3973 | 3974 | |
3974 | 3975 |
return self.create_export(formdef, fields, items, total_count) |
3975 | 3976 | |
... | ... | |
3980 | 3981 |
if not self.kwargs.get('skip_header_line'): |
3981 | 3982 |
csv_output.writerow(self.csv_tuple_heading(fields)) |
3982 | 3983 | |
3983 |
for filled in items:
|
|
3984 |
for i, filled in enumerate(items):
|
|
3984 | 3985 |
csv_output.writerow(tuple(x['value'] for x in self.get_spreadsheet_line(fields, filled))) |
3986 |
self.increment_count() |
|
3985 | 3987 | |
3986 | 3988 |
self.file_content = output.getvalue() |
3987 | 3989 |
self.content_type = 'text/csv' |
... | ... | |
4025 | 4027 |
data_field=item['field'], |
4026 | 4028 |
native_value=item['native_value'], |
4027 | 4029 |
) |
4030 |
self.increment_count() |
|
4028 | 4031 | |
4029 | 4032 |
output = io.BytesIO() |
4030 | 4033 |
workbook.save(output) |
wcs/qommon/afterjobs.py | ||
---|---|---|
35 | 35 | |
36 | 36 |
response = get_response() |
37 | 37 |
response.set_content_type('text/plain') |
38 |
if not job.completion_status: |
|
38 |
completion_status = job.get_completion_status() |
|
39 |
if not completion_status: |
|
39 | 40 |
return job.status + '|' + str(_(job.status)) |
40 |
return job.status + '|' + str(_(job.status)) + ' ' + job.completion_status
|
|
41 |
return job.status + '|' + str(_(job.status)) + ' ' + str(completion_status)
|
|
41 | 42 | |
42 | 43 | |
43 | 44 |
class AfterJob(StorableObject): |
... | ... | |
48 | 49 |
status = None |
49 | 50 |
creation_time = None |
50 | 51 |
completion_time = None |
51 |
completion_status = None |
|
52 |
current_count = None |
|
53 |
total_count = None |
|
52 | 54 | |
53 | 55 |
execute = None |
54 | 56 | |
... | ... | |
73 | 75 |
def done_action_attributes(self): |
74 | 76 |
return self.done_button_attributes_arg |
75 | 77 | |
78 |
def increment_count(self): |
|
79 |
self.current_count = (self.current_count or 0) + 1 |
|
80 |
self.store() |
|
81 | ||
82 |
def get_completion_status(self): |
|
83 |
current_count = self.current_count or 0 |
|
84 | ||
85 |
if not current_count: |
|
86 |
return '' |
|
87 | ||
88 |
if not self.total_count: |
|
89 |
return _(f'{current_count} (unknown total)') |
|
90 | ||
91 |
percent = int(current_count * 100 / self.total_count) |
|
92 |
return _(f'{current_count}/{self.total_count} ({percent}%)') |
|
93 | ||
76 | 94 |
def run(self, spool=False): |
77 | 95 |
if self.completion_time: |
78 | 96 |
return |
79 |
- |