misc: do not compute drafts info when comparing snapshots (#89799)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-04-19 14:01:14 +02:00
parent 291fea5b8b
commit 61ce06676d
1 changed files with 45 additions and 43 deletions

View File

@ -1754,7 +1754,10 @@ class FormDefPage(Directory, TempfileDirectoryMixin, DocumentableMixin):
else:
role_label = '-'
view.role = role_label
context['custom_views'] = sorted(custom_views, key=lambda x: getattr(x, 'title'))
context['is_carddef'] = isinstance(self.formdef, CardDef)
if not hasattr(self.formdef, 'snapshot_object'):
deprecations = DeprecationsDirectory()
context['deprecations'] = deprecations.get_deprecations(
@ -1762,54 +1765,53 @@ class FormDefPage(Directory, TempfileDirectoryMixin, DocumentableMixin):
)
context['deprecation_titles'] = deprecations.titles
receipt_time_criteria = GreaterOrEqual(
'receipt_time',
datetime.datetime.now() - datetime.timedelta(days=self.formdef.get_drafts_lifespan()),
)
receipt_time_criteria = GreaterOrEqual(
'receipt_time',
datetime.datetime.now() - datetime.timedelta(days=self.formdef.get_drafts_lifespan()),
)
temp_drafts = defaultdict(int)
for formdata in self.formdef.data_class().select_iterator(
clause=[Equal('status', 'draft'), receipt_time_criteria], itersize=200
):
page_id = formdata.page_id if formdata.page_id is not None else '_unknown'
temp_drafts[page_id] += 1
temp_drafts = defaultdict(int)
for formdata in self.formdef.data_class().select_iterator(
clause=[Equal('status', 'draft'), receipt_time_criteria], itersize=200
):
page_id = formdata.page_id if formdata.page_id is not None else '_unknown'
temp_drafts[page_id] += 1
total_drafts = sum(temp_drafts.values()) if temp_drafts else 0
drafts = {}
special_page_index_mapping = {
'_first_page': -1000, # first
'_unknown': 1000, # last
'_confirmation_page': 999, # second to last
}
if total_drafts:
for page_id, page_index in special_page_index_mapping.items():
try:
page_total = temp_drafts.pop(page_id)
except KeyError:
page_total = 0
drafts[page_id] = {'total': page_total, 'field': None, 'page_index': page_index}
for page_id, page_total in temp_drafts.items():
for index, field in enumerate(self.formdef.iter_fields(with_backoffice_fields=False)):
if page_id == field.id and isinstance(field, PageField):
drafts[page_id] = {
'total': page_total,
'field': field,
'page_index': index,
}
break
else:
drafts['_unknown']['total'] += page_total
total_drafts = sum(temp_drafts.values()) if temp_drafts else 0
drafts = {}
special_page_index_mapping = {
'_first_page': -1000, # first
'_unknown': 1000, # last
'_confirmation_page': 999, # second to last
}
if total_drafts:
for page_id, page_index in special_page_index_mapping.items():
try:
page_total = temp_drafts.pop(page_id)
except KeyError:
page_total = 0
drafts[page_id] = {'total': page_total, 'field': None, 'page_index': page_index}
for page_id, page_total in temp_drafts.items():
for index, field in enumerate(self.formdef.iter_fields(with_backoffice_fields=False)):
if page_id == field.id and isinstance(field, PageField):
drafts[page_id] = {
'total': page_total,
'field': field,
'page_index': index,
}
break
else:
drafts['_unknown']['total'] += page_total
for draft_data in drafts.values():
draft_data['percent'] = 100 * draft_data['total'] / total_drafts
for draft_data in drafts.values():
draft_data['percent'] = 100 * draft_data['total'] / total_drafts
total_formdata = self.formdef.data_class().count([receipt_time_criteria])
context['drafts'] = sorted(drafts.items(), key=lambda x: x[1]['page_index'])
context['percent_submitted_formdata'] = 100 * (total_formdata - total_drafts) / total_formdata
context['total_formdata'] = total_formdata
total_formdata = self.formdef.data_class().count([receipt_time_criteria])
context['drafts'] = sorted(drafts.items(), key=lambda x: x[1]['page_index'])
context['percent_submitted_formdata'] = 100 * (total_formdata - total_drafts) / total_formdata
context['total_formdata'] = total_formdata
context['total_drafts'] = total_drafts
context['is_carddef'] = isinstance(self.formdef, CardDef)
context['total_drafts'] = total_drafts
return template.QommonTemplateResponse(
templates=[self.inspect_template_name],