feat: Show short description for ANs with one picture

This commit is contained in:
2025-09-07 20:36:41 +02:00
parent f784ab0c78
commit 3da6e90f73
3 changed files with 36 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ from django.utils import timezone
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from docutils.nodes import description
from .tools import misc, geo from .tools import misc, geo
from notfellchen.settings import MEDIA_URL, base_url from notfellchen.settings import MEDIA_URL, base_url
@@ -444,12 +445,22 @@ class AdoptionNotice(models.Model):
else: else:
return self.location.latitude, self.location.longitude return self.location.latitude, self.location.longitude
@property def _get_short_description(self, length: int) -> str:
def description_short(self):
if self.description is None: if self.description is None:
return "" return ""
if len(self.description) > 200: elif len(self.description) > length:
return self.description[:200] + f" ... [weiterlesen]({self.get_absolute_url()})" 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): def get_absolute_url(self):
"""Returns the url to access a detailed page for the adoption notice.""" """Returns the url to access a detailed page for the adoption notice."""

View File

@@ -234,7 +234,7 @@ IMAGES
.thumbnail img { .thumbnail img {
width: 100%; width: 100%;
height: 50px; height: 70px;
object-fit: cover; /* Crops the images */ object-fit: cover; /* Crops the images */
border-radius: 4px; border-radius: 4px;
} }

View File

@@ -54,7 +54,7 @@
</a> </a>
</div> </div>
{% endwith %} {% endwith %}
{% if adoption_notice.get_photos|length > 1 %}
<div class="thumbnail-row minimal"> <div class="thumbnail-row minimal">
{% for photo in adoption_notice.get_photos|slice:"1:4" %} {% for photo in adoption_notice.get_photos|slice:"1:4" %}
<div class="thumbnail"> <div class="thumbnail">
@@ -68,6 +68,13 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% else %}
{% if adoption_notice.description_100_short %}
<div class="content">
{{ adoption_notice.description_100_short | render_markdown }}
</div>
{% endif %}
{% endif %}
</div> </div>
{% else %} {% else %}
{% if adoption_notice.description_short %} {% if adoption_notice.description_short %}