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