feat: Represent last checked more human-readable
This commit is contained in:
parent
a8c837e9f6
commit
561a30b7ab
@ -12,6 +12,7 @@ from django.contrib.auth.models import AbstractUser
|
|||||||
from .tools import misc, geo
|
from .tools import misc, geo
|
||||||
from notfellchen.settings import MEDIA_URL
|
from notfellchen.settings import MEDIA_URL
|
||||||
from .tools.geo import LocationProxy
|
from .tools.geo import LocationProxy
|
||||||
|
from .tools.misc import age_as_hr_string, time_since_as_hr_string
|
||||||
|
|
||||||
|
|
||||||
class Language(models.Model):
|
class Language(models.Model):
|
||||||
@ -257,6 +258,13 @@ class AdoptionNotice(models.Model):
|
|||||||
sexes.add(animal.sex)
|
sexes.add(animal.sex)
|
||||||
return sexes
|
return sexes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_checked_hr(self):
|
||||||
|
time_since_last_checked = timezone.now() - self.last_checked
|
||||||
|
print(time_since_as_hr_string(time_since_last_checked))
|
||||||
|
return time_since_as_hr_string(time_since_last_checked)
|
||||||
|
|
||||||
|
|
||||||
def sex_code(self):
|
def sex_code(self):
|
||||||
# Treat Intersex as mixed in order to increase their visibility
|
# Treat Intersex as mixed in order to increase their visibility
|
||||||
if len(self.sexes) > 1:
|
if len(self.sexes) > 1:
|
||||||
|
@ -77,7 +77,8 @@
|
|||||||
|
|
||||||
<td data-label="{% trans 'Suchen seit' %}">{{ adoption_notice.searching_since }}</td>
|
<td data-label="{% trans 'Suchen seit' %}">{{ adoption_notice.searching_since }}</td>
|
||||||
<td data-label="{% trans 'Zuletzt aktualisiert' %}">
|
<td data-label="{% trans 'Zuletzt aktualisiert' %}">
|
||||||
{{ adoption_notice.last_checked | date:'d. F Y' }}</td>
|
{{ adoption_notice.last_checked_hr }}
|
||||||
|
</td>
|
||||||
<td data-label="{% trans 'Weitere Informationen' %}">
|
<td data-label="{% trans 'Weitere Informationen' %}">
|
||||||
{% if adoption_notice.further_information %}
|
{% if adoption_notice.further_information %}
|
||||||
<form method="get" action="{% url 'external-site' %}">
|
<form method="get" action="{% url 'external-site' %}">
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import datetime as datetime
|
import datetime as datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from django.utils.translation import ngettext
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from notfellchen import settings
|
from notfellchen import settings
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -29,6 +32,37 @@ def age_as_hr_string(age: datetime.timedelta) -> str:
|
|||||||
return f'{days:.0f} Tag{pluralize(days)}'
|
return f'{days:.0f} Tag{pluralize(days)}'
|
||||||
|
|
||||||
|
|
||||||
|
def time_since_as_hr_string(age: datetime.timedelta) -> str:
|
||||||
|
days = age.days
|
||||||
|
weeks = age.days / 7
|
||||||
|
months = age.days / 30
|
||||||
|
years = age.days / 365
|
||||||
|
if years >= 1:
|
||||||
|
text = ngettext(
|
||||||
|
"vor einem Jahr",
|
||||||
|
"vor %(years) Tagen",
|
||||||
|
years,
|
||||||
|
) % {
|
||||||
|
"years": years,
|
||||||
|
}
|
||||||
|
elif months >= 3:
|
||||||
|
_("vor %(month) Monaten") % {"month": months}
|
||||||
|
elif weeks >= 3:
|
||||||
|
text = _("vor %(weeks) Wochen") % {"weeks": weeks}
|
||||||
|
else:
|
||||||
|
if days == 0:
|
||||||
|
text = _("Heute")
|
||||||
|
else:
|
||||||
|
text = ngettext(
|
||||||
|
"vor einem Tag",
|
||||||
|
"vor %(count)d Tagen",
|
||||||
|
days,
|
||||||
|
) % {
|
||||||
|
"count": days,
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def healthcheck_ok():
|
def healthcheck_ok():
|
||||||
try:
|
try:
|
||||||
requests.get(settings.HEALTHCHECKS_URL, timeout=10)
|
requests.get(settings.HEALTHCHECKS_URL, timeout=10)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user