From 3da6e90f73781955753942e649ce656ed748abc0 Mon Sep 17 00:00:00 2001 From: moanos Date: Sun, 7 Sep 2025 20:36:41 +0200 Subject: [PATCH] feat: Show short description for ANs with one picture --- src/fellchensammlung/models.py | 19 ++++++++--- .../static/fellchensammlung/css/main.scss | 2 +- .../partial-adoption-notice-minimal.html | 33 +++++++++++-------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 1ab40ba..8cbf9f0 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -6,6 +6,7 @@ from django.utils import timezone from django.contrib.auth.models import Group from django.contrib.auth.models import AbstractUser from django.core.exceptions import ValidationError +from docutils.nodes import description from .tools import misc, geo from notfellchen.settings import MEDIA_URL, base_url @@ -444,12 +445,22 @@ class AdoptionNotice(models.Model): else: return self.location.latitude, self.location.longitude - @property - def description_short(self): + def _get_short_description(self, length: int) -> str: if self.description is None: return "" - if len(self.description) > 200: - return self.description[:200] + f" ... [weiterlesen]({self.get_absolute_url()})" + elif len(self.description) > length: + return self.description[:length] + f" ... [weiterlesen]({self.get_absolute_url()})" + else: + return self.description + + @property + def description_short(self): + return self._get_short_description(200) + + @property + def description_100_short(self): + return self._get_short_description(90) + def get_absolute_url(self): """Returns the url to access a detailed page for the adoption notice.""" diff --git a/src/fellchensammlung/static/fellchensammlung/css/main.scss b/src/fellchensammlung/static/fellchensammlung/css/main.scss index 11a33f0..877f668 100644 --- a/src/fellchensammlung/static/fellchensammlung/css/main.scss +++ b/src/fellchensammlung/static/fellchensammlung/css/main.scss @@ -234,7 +234,7 @@ IMAGES .thumbnail img { width: 100%; - height: 50px; + height: 70px; object-fit: cover; /* Crops the images */ border-radius: 4px; } diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-adoption-notice-minimal.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-adoption-notice-minimal.html index d54d16d..d94c40c 100644 --- a/src/fellchensammlung/templates/fellchensammlung/partials/partial-adoption-notice-minimal.html +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-adoption-notice-minimal.html @@ -54,20 +54,27 @@ {% endwith %} - -
- {% for photo in adoption_notice.get_photos|slice:"1:4" %} -
- - {{ photo.alt_text }} - + {% if adoption_notice.get_photos|length > 1 %} +
+ {% for photo in adoption_notice.get_photos|slice:"1:4" %} +
+ + {{ photo.alt_text }} + +
+ {% endfor %} +
+ {% else %} + {% if adoption_notice.description_100_short %} +
+ {{ adoption_notice.description_100_short | render_markdown }}
- {% endfor %} -
+ {% endif %} + {% endif %}
{% else %} {% if adoption_notice.description_short %}