mirror of
https://github.com/ae-utbm/sith.git
synced 2025-11-25 14:16:56 +00:00
refactor: format_timedelta template filter
This commit is contained in:
@@ -55,31 +55,17 @@ def phonenumber(
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="truncate_time")
|
|
||||||
def truncate_time(value, time_unit):
|
|
||||||
"""Remove everything in the time format lower than the specified unit.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
value: the value to truncate
|
|
||||||
time_unit: the lowest unit to display
|
|
||||||
"""
|
|
||||||
value = str(value)
|
|
||||||
return {
|
|
||||||
"millis": lambda: value.split(".")[0],
|
|
||||||
"seconds": lambda: value.rsplit(":", maxsplit=1)[0],
|
|
||||||
"minutes": lambda: value.split(":", maxsplit=1)[0],
|
|
||||||
"hours": lambda: value.rsplit(" ")[0],
|
|
||||||
}[time_unit]()
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="format_timedelta")
|
@register.filter(name="format_timedelta")
|
||||||
def format_timedelta(value: datetime.timedelta) -> str:
|
def format_timedelta(value: datetime.timedelta) -> str:
|
||||||
|
value = value - datetime.timedelta(microseconds=value.microseconds)
|
||||||
days = value.days
|
days = value.days
|
||||||
if days == 0:
|
if days == 0:
|
||||||
return str(value)
|
return str(value)
|
||||||
remainder = value - datetime.timedelta(days=days)
|
remainder = value - datetime.timedelta(days=days)
|
||||||
return ngettext(
|
return ngettext(
|
||||||
"%(nb_days)d day, %(remainder)s", "%(nb_days)d days, %(remainder)s", days
|
"%(nb_days)d day, %(remainder)s",
|
||||||
|
"%(nb_days)d days, %(remainder)s",
|
||||||
|
days,
|
||||||
) % {"nb_days": days, "remainder": str(remainder)}
|
) % {"nb_days": days, "remainder": str(remainder)}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
<td>{{ loop.index }}</td>
|
<td>{{ loop.index }}</td>
|
||||||
<td>{{ barman.name }} {% if barman.nickname %}({{ barman.nickname }}){% endif %}</td>
|
<td>{{ barman.name }} {% if barman.nickname %}({{ barman.nickname }}){% endif %}</td>
|
||||||
<td>{{ barman.promo or '' }}</td>
|
<td>{{ barman.promo or '' }}</td>
|
||||||
<td>{{ barman.perm_sum|format_timedelta|truncate_time("millis") }}</td>
|
<td>{{ barman.perm_sum|format_timedelta }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
<td>{{ loop.index }}</td>
|
<td>{{ loop.index }}</td>
|
||||||
<td>{{ barman.name }} {% if barman.nickname %}({{ barman.nickname }}){% endif %}</td>
|
<td>{{ barman.name }} {% if barman.nickname %}({{ barman.nickname }}){% endif %}</td>
|
||||||
<td>{{ barman.promo or '' }}</td>
|
<td>{{ barman.promo or '' }}</td>
|
||||||
<td>{{ barman.perm_sum|format_timedelta|truncate_time("millis") }}</td>
|
<td>{{ barman.perm_sum|format_timedelta }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2025-11-19 21:00+0100\n"
|
"POT-Creation-Date: 2025-11-24 11:05+0100\n"
|
||||||
"PO-Revision-Date: 2016-07-18\n"
|
"PO-Revision-Date: 2016-07-18\n"
|
||||||
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
||||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||||
@@ -2819,8 +2819,8 @@ msgstr "Outils Trombi"
|
|||||||
#, python-format
|
#, python-format
|
||||||
msgid "%(nb_days)d day, %(remainder)s"
|
msgid "%(nb_days)d day, %(remainder)s"
|
||||||
msgid_plural "%(nb_days)d days, %(remainder)s"
|
msgid_plural "%(nb_days)d days, %(remainder)s"
|
||||||
msgstr[0] ""
|
msgstr[0] "%(nb_days)d jour, %(remainder)s"
|
||||||
msgstr[1] ""
|
msgstr[1] "%(nb_days)d jours, %(remainder)s"
|
||||||
|
|
||||||
#: core/views/files.py
|
#: core/views/files.py
|
||||||
msgid "Add a new folder"
|
msgid "Add a new folder"
|
||||||
|
|||||||
@@ -177,7 +177,6 @@ TEMPLATES = [
|
|||||||
"filters": {
|
"filters": {
|
||||||
"markdown": "core.templatetags.renderer.markdown",
|
"markdown": "core.templatetags.renderer.markdown",
|
||||||
"phonenumber": "core.templatetags.renderer.phonenumber",
|
"phonenumber": "core.templatetags.renderer.phonenumber",
|
||||||
"truncate_time": "core.templatetags.renderer.truncate_time",
|
|
||||||
"format_timedelta": "core.templatetags.renderer.format_timedelta",
|
"format_timedelta": "core.templatetags.renderer.format_timedelta",
|
||||||
"add_attr": "core.templatetags.renderer.add_attr",
|
"add_attr": "core.templatetags.renderer.add_attr",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user