feat: Show nicer time of creating the notification
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
</form>
|
||||
<div class="notification-header">
|
||||
<a href="{{ notification.url }}"><b>{{ notification.title }}</b></a>
|
||||
<i class="card-timestamp">{{ notification.created_at }}</i>
|
||||
<i class="card-timestamp">{{ notification.created_at|time_since_hr }}</i>
|
||||
</div>
|
||||
<div class="notification-body">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
|
@@ -4,7 +4,9 @@ from django import template
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.utils.safestring import mark_safe
|
||||
from urllib.parse import urlparse
|
||||
from django.utils import timezone
|
||||
|
||||
from fellchensammlung.tools.misc import time_since_as_hr_string
|
||||
from notfellchen import settings
|
||||
from fellchensammlung.models import TrustLevel
|
||||
|
||||
@@ -114,3 +116,9 @@ def dictkey(d, key):
|
||||
def host():
|
||||
# Will not work for localhost or deployments without https
|
||||
return f"https://{settings.host}"
|
||||
|
||||
|
||||
@register.filter
|
||||
def time_since_hr(timestamp):
|
||||
t_delta = timezone.now() - timestamp
|
||||
return time_since_as_hr_string(t_delta)
|
||||
|
@@ -37,6 +37,8 @@ def time_since_as_hr_string(age: datetime.timedelta) -> str:
|
||||
weeks = age.days / 7
|
||||
months = age.days / 30
|
||||
years = age.days / 365
|
||||
minutes = age.seconds / 60
|
||||
hours = age.seconds / 3600
|
||||
if years >= 1:
|
||||
text = ngettext(
|
||||
"vor einem Jahr",
|
||||
@@ -49,11 +51,14 @@ def time_since_as_hr_string(age: datetime.timedelta) -> str:
|
||||
text = _("vor %(month)d Monaten") % {"month": months}
|
||||
elif weeks >= 3:
|
||||
text = _("vor %(weeks)d Wochen") % {"weeks": weeks}
|
||||
elif days >= 1:
|
||||
text = ngettext("vor einem Tag","vor %(count)d Tagen", days,) % {"count": days,}
|
||||
elif hours >= 1:
|
||||
text = ngettext("vor einer Stunde", "vor %(count)d Stunden", hours,) % {"count": hours,}
|
||||
elif minutes >= 1:
|
||||
text = ngettext("vor einer Minute", "vor %(count)d Minuten", minutes, ) % {"count": minutes, }
|
||||
else:
|
||||
if days == 0:
|
||||
text = _("Heute")
|
||||
else:
|
||||
text = ngettext("vor einem Tag","vor %(count)d Tagen", days,) % {"count": days,}
|
||||
text = _("Gerade eben")
|
||||
return text
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user