backoffice: revamp look of bars for items/bools (#6893)
This commit is contained in:
parent
bfc0d859db
commit
5797c76e47
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB |
|
@ -619,6 +619,8 @@ class BoolField(WidgetField):
|
|||
|
||||
def stats(self, values):
|
||||
no_records = len(values)
|
||||
if not no_records:
|
||||
return
|
||||
r = TemplateIO(html = True)
|
||||
r += htmltext('<table class="stats">')
|
||||
r += htmltext('<thead><tr><th colspan="4">')
|
||||
|
@ -631,26 +633,24 @@ class BoolField(WidgetField):
|
|||
r += htmltext('<td class="label">')
|
||||
if o is True:
|
||||
r += _('Yes')
|
||||
value = True
|
||||
else:
|
||||
r += _('No')
|
||||
value = False
|
||||
r += htmltext('</td>')
|
||||
no = len([None for x in values if self.convert_value_from_str(x.data.get(self.id)) is value])
|
||||
|
||||
r += htmltext('<td class="percent">')
|
||||
r += htmltext(' %.2f %%') % (100.*no/no_records)
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('<td class="total">')
|
||||
r += '(%d/%d)' % (no, no_records)
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('</tr>')
|
||||
r += htmltext('<tr>')
|
||||
r += htmltext('<td class="bar" colspan="3">')
|
||||
r += htmltext('<span style="width: %d%%"></span>' % (100*no/no_records))
|
||||
r += htmltext('</td>')
|
||||
no = len([None for x in values if x.data.get(self.id) == str(o)])
|
||||
if no_records:
|
||||
r += htmltext('<td class="percent">')
|
||||
r += ' %.2f %%' % (100.*no/no_records)
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('<td class="total">')
|
||||
r += '(%d/%d)' % (no, no_records)
|
||||
r += htmltext('</td>')
|
||||
image_len = 300.*no/no_records
|
||||
r += htmltext('<td>')
|
||||
if image_len:
|
||||
r += htmltext('<img class="bar" src="%simages/bar.png" height="20px" alt="" '
|
||||
'width="%dpx" />' % (get_publisher().get_root_url(), image_len))
|
||||
r += htmltext('</td>')
|
||||
else:
|
||||
r += htmltext('<td colspan="3"></td>')
|
||||
#'NaN'
|
||||
r += htmltext('</tr>')
|
||||
r += htmltext('</tbody>')
|
||||
r += htmltext('</table>')
|
||||
|
@ -793,6 +793,8 @@ def item_items_stats(field, values):
|
|||
if len(options) == 0:
|
||||
return None
|
||||
no_records = len(values)
|
||||
if no_records == 0:
|
||||
return None
|
||||
r = TemplateIO(html = True)
|
||||
r += htmltext('<table class="stats">')
|
||||
r += htmltext('<thead><tr><th colspan="4">')
|
||||
|
@ -800,36 +802,32 @@ def item_items_stats(field, values):
|
|||
r += htmltext('</th></tr></thead>')
|
||||
r += htmltext('<tbody>')
|
||||
for option in options:
|
||||
r += htmltext('<tr>')
|
||||
r += htmltext('<td class="label">')
|
||||
if type(option) in (tuple, list):
|
||||
option_label = option[1]
|
||||
option_value = str(option[0])
|
||||
else:
|
||||
option_label = option
|
||||
option_value = option
|
||||
r += option_label
|
||||
r += htmltext('</td>')
|
||||
if field.type == 'item':
|
||||
no = len([None for x in values if x.data.get(field.id) == option_value])
|
||||
else:
|
||||
no = len([None for x in values if option_value in (x.data.get(field.id) or [])])
|
||||
if no_records:
|
||||
r += htmltext('<td class="percent">')
|
||||
r += ' %.2f %%' % (100.*no/no_records)
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('<td class="total">')
|
||||
r += '(%d/%d)' % (no, no_records)
|
||||
r += htmltext('</td>')
|
||||
image_len = 300.*no/no_records
|
||||
r += htmltext('<td>')
|
||||
if image_len:
|
||||
r += htmltext('<img class="bar" src="%simages/bar.png" height="20px" alt="" '
|
||||
'width="%dpx" />' % (get_publisher().get_root_url(), image_len))
|
||||
r += htmltext('</td>')
|
||||
else:
|
||||
r += htmltext('<td colspan="3"></td>')
|
||||
#'NaN'
|
||||
r += htmltext('<tr>')
|
||||
r += htmltext('<td class="label">')
|
||||
r += option_label
|
||||
r += htmltext('</td>')
|
||||
|
||||
r += htmltext('<td class="percent">')
|
||||
r += htmltext(' %.2f %%') % (100.*no/no_records)
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('<td class="total">')
|
||||
r += '(%d/%d)' % (no, no_records)
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('</tr>')
|
||||
r += htmltext('<tr>')
|
||||
r += htmltext('<td class="bar" colspan="3">')
|
||||
r += htmltext('<span style="width: %d%%"></span>' % (100*no/no_records))
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('</tr>')
|
||||
r += htmltext('</tbody>')
|
||||
r += htmltext('</table>')
|
||||
|
|
|
@ -272,6 +272,7 @@ span.error-message {
|
|||
|
||||
table.stats {
|
||||
margin: 1ex 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.stats thead th {
|
||||
|
@ -282,6 +283,18 @@ table.stats td {
|
|||
padding-left: 1em;
|
||||
}
|
||||
|
||||
table.stats td.label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.stats td.bar span {
|
||||
background: #4BB2C5;
|
||||
height: 1ex;
|
||||
display: block;
|
||||
margin-bottom: 1ex;
|
||||
box-shadow: 2px 2px 2px #aaa;
|
||||
}
|
||||
|
||||
form.inplaceeditor-form {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
|
Loading…
Reference in New Issue