backoffice: display drafts stats (#72542)
gitea/wcs/pipeline/head There was a failure building this commit
Details
gitea/wcs/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
4ef907d7f8
commit
851a1d751d
|
@ -28,6 +28,7 @@ from wcs.backoffice.deprecations import DeprecationsDirectory
|
|||
from wcs.backoffice.snapshots import SnapshotsDirectory
|
||||
from wcs.carddef import CardDef
|
||||
from wcs.categories import Category
|
||||
from wcs.fields import PageField
|
||||
from wcs.formdef import (
|
||||
DRAFTS_DEFAULT_LIFESPAN,
|
||||
FormDef,
|
||||
|
@ -1760,6 +1761,35 @@ class FormDefPage(Directory, TempfileDirectoryMixin):
|
|||
f'{self.formdef.xml_root_node}:{self.formdef.id}'
|
||||
)
|
||||
context['deprecation_titles'] = deprecations.titles
|
||||
|
||||
temp_drafts = defaultdict(int)
|
||||
total_drafts = 0
|
||||
for formdata in self.formdef.data_class().select(clause=[Equal('status', 'draft')]):
|
||||
page_id = formdata.page_id if formdata.page_id is not None else '_unkown'
|
||||
temp_drafts[page_id] += 1
|
||||
total_drafts += 1
|
||||
drafts = {}
|
||||
if total_drafts:
|
||||
for key in ('_unkown', '_confirmation_page', '_first_page'):
|
||||
try:
|
||||
num_drafts = temp_drafts.pop(key)
|
||||
except KeyError:
|
||||
num_drafts = 0
|
||||
drafts[key] = {'total': num_drafts, 'field': None}
|
||||
for page_id, num_drafts in temp_drafts.items():
|
||||
for field in self.formdef.iter_fields(with_backoffice_fields=False):
|
||||
if page_id == field.id and isinstance(field, PageField):
|
||||
drafts[page_id] = {'total': num_drafts, 'field': field}
|
||||
break
|
||||
else:
|
||||
drafts['_unkown']['total'] += num_drafts
|
||||
for draft_data in drafts.values():
|
||||
draft_percent = 100 * draft_data['total'] / total_drafts
|
||||
draft_data['percent'] = draft_percent
|
||||
draft_data['percent_rounded'] = '%d' % draft_percent
|
||||
context['drafts'] = sorted(drafts.items(), reverse=True, key=lambda x: x[1]['total'])
|
||||
context['drafts_total'] = total_drafts
|
||||
|
||||
return template.QommonTemplateResponse(
|
||||
templates=[self.inspect_template_name],
|
||||
context=context,
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
<button role="tab" aria-selected="false" aria-controls="inspect-workflow" id="tab-workflow" tabindex="-1">{% trans "Workflow" %}</button>
|
||||
<button role="tab" aria-selected="false" aria-controls="inspect-options" id="tab-options" tabindex="-1">{% trans "Options" %}</button>
|
||||
<button role="tab" aria-selected="false" aria-controls="inspect-fields" id="tab-fields" tabindex="-1">{% trans "Fields" %}</button>
|
||||
{% if not snapshots_diff %}
|
||||
<button role="tab" aria-selected="false" aria-controls="inspect-drafts" id="tab-drafts" tabindex="-1">{% trans "Drafts" %}</button>
|
||||
{% endif %}
|
||||
{% if custom_views %}
|
||||
<button role="tab" aria-selected="false" aria-controls="inspect-customviews" id="tab-customviews" tabindex="-1">{% trans "Custom views" %}</button>
|
||||
{% endif %}
|
||||
|
@ -88,6 +91,41 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div id="inspect-drafts" role="tabpanel" tabindex="0" aria-labelledby="tab-drafts" hidden>
|
||||
<h3>{% trans "Drafts" %}</h3>
|
||||
<table class="stats">
|
||||
<thead><tr><th colspan="4">{% trans "Page" %}</th></tr></thead>
|
||||
<tbody>
|
||||
{% for page_drafts in drafts %}
|
||||
{% with page_id=page_drafts.0 draft_data=page_drafts.1 %}
|
||||
{% if draft_data.total %}
|
||||
<tr>
|
||||
<td class="label">
|
||||
{% if page_id == "_unkown" %}
|
||||
{% trans "Unkown" %}
|
||||
{% elif page_id == "_first_page" %}
|
||||
{% trans "Only page" %}
|
||||
{% elif page_id == "_confirmation_page" %}
|
||||
{% trans "Confirmation page" %}
|
||||
{% else %}
|
||||
{{ draft_data.field.ellipsized_label }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="percent"> {{draft_data.percent}} %</td>
|
||||
<td class="total">({{draft_data.total}}/{{drafts_total}})</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="bar" colspan="3">
|
||||
<span style="width: {{draft_data.percent_rounded}}%"></span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="inspect-customviews" role="tabpanel" tabindex="0" aria-labelledby="tab-customviews" hidden>
|
||||
<div>
|
||||
{% for custom_view in custom_views %}
|
||||
|
|
Loading…
Reference in New Issue