From dda400f3ba1cde8923ba34476523c5ac163bbbc0 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 19 Mar 2024 07:02:32 +0100 Subject: [PATCH] feat: Add animal detail view --- .../migrations/0005_animal_sex.py | 19 +++++++++++++++ .../0006_alter_animal_date_of_birth.py | 20 ++++++++++++++++ .../fellchensammlung/detail_animal.html | 23 ++++++++++++++++++ src/fellchensammlung/tools/misc.py | 24 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/fellchensammlung/migrations/0005_animal_sex.py create mode 100644 src/fellchensammlung/migrations/0006_alter_animal_date_of_birth.py create mode 100644 src/fellchensammlung/templates/fellchensammlung/detail_animal.html create mode 100644 src/fellchensammlung/tools/misc.py diff --git a/src/fellchensammlung/migrations/0005_animal_sex.py b/src/fellchensammlung/migrations/0005_animal_sex.py new file mode 100644 index 0000000..206afbf --- /dev/null +++ b/src/fellchensammlung/migrations/0005_animal_sex.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.3 on 2024-03-19 04:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0004_image_adoptionnotice_photos_animal_photos'), + ] + + operations = [ + migrations.AddField( + model_name='animal', + name='sex', + field=models.CharField(choices=[('M_N', 'male_neutered'), ('M', 'male'), ('F_N', 'female_neutered'), ('F', 'female')], default='female', max_length=20), + preserve_default=False, + ), + ] diff --git a/src/fellchensammlung/migrations/0006_alter_animal_date_of_birth.py b/src/fellchensammlung/migrations/0006_alter_animal_date_of_birth.py new file mode 100644 index 0000000..51dd8ca --- /dev/null +++ b/src/fellchensammlung/migrations/0006_alter_animal_date_of_birth.py @@ -0,0 +1,20 @@ +# Generated by Django 5.0.3 on 2024-03-19 04:51 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0005_animal_sex'), + ] + + operations = [ + migrations.AlterField( + model_name='animal', + name='date_of_birth', + field=models.DateField(default=datetime.datetime(2024, 3, 19, 4, 51, 44, 367516, tzinfo=datetime.timezone.utc), verbose_name='Date of birth'), + preserve_default=False, + ), + ] diff --git a/src/fellchensammlung/templates/fellchensammlung/detail_animal.html b/src/fellchensammlung/templates/fellchensammlung/detail_animal.html new file mode 100644 index 0000000..4dd03ba --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/detail_animal.html @@ -0,0 +1,23 @@ +{% extends "fellchensammlung/base_generic.html" %} +{% load custom_tags %} +{% load i18n %} + +{% block content %} +
+

{{ animal.name }}

+
{{ animal.species }}
+
+
+ + + + + + + + + +
AlterGeschlecht
{{ animal.hr_age }}{{ animal.sex }}
+
+

{{ animal.description }}

+{% endblock %} diff --git a/src/fellchensammlung/tools/misc.py b/src/fellchensammlung/tools/misc.py new file mode 100644 index 0000000..e898436 --- /dev/null +++ b/src/fellchensammlung/tools/misc.py @@ -0,0 +1,24 @@ +import datetime as datetime + + +def pluralize(number, letter="e"): + try: + size = len(number) + except TypeError: + size = int(number) + return '' if size == 1 else letter + + +def age_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: + return f'{years} Jahr{pluralize(years)} und {months} Monat{pluralize(months)}' + elif months >= 3: + return f'{months} Monat{pluralize(months)}' + elif weeks >= 3: + return f'{weeks} Woche{pluralize(weeks, "n")}' + else: + return f'{days} Tag{pluralize(days)}'