Coverage for website/photos/templatetags/photos_cards.py: 80.49%
35 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1from django import template
2from django.template.defaultfilters import date
3from django.urls import reverse
5from thaliawebsite.templatetags.grid_item import grid_item
6from utils.media.services import get_media_url
8register = template.Library()
11@register.inclusion_tag("includes/grid_item.html")
12def album_card(album):
13 """Create a card to show on a page of multiple albums."""
14 class_name = "album-card"
15 image_url = ""
17 if album.cover: 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true
18 image_url = album.cover.file.thumbnails.medium.url
20 url = album.get_absolute_url
21 if not album.accessible: 21 ↛ 22line 21 didn't jump to line 22 because the condition on line 21 was never true
22 class_name += " grayscale"
23 url = None
25 return grid_item(
26 title=album.title,
27 meta_text=f'<p>{date(album.date, "Y-m-d")}</p>',
28 url=url,
29 image_url=image_url,
30 class_name=class_name,
31 )
34@register.inclusion_tag("includes/grid_item.html")
35def photo_card(photo):
36 """Create a card of a photo to show on an album page."""
37 class_name = "photo-card"
38 anchor_attrs = 'data-fancybox="gallery"'
40 if photo.album.shareable:
41 url = reverse(
42 "photos:shared-download",
43 args=[photo.album.slug, photo.album.access_token, photo],
44 )
45 anchor_attrs += f" data-download-src={url}"
46 else:
47 url = reverse("photos:download", args=[photo.album.slug, photo])
48 anchor_attrs += f" data-download-src={url}"
50 anchor_attrs += f" data-numLikes='{photo.num_likes}'"
51 anchor_attrs += (
52 f" data-likeUrl={reverse('api:v2:photos:photo-like', args=[photo.pk])}"
53 )
55 image_url = get_media_url(photo.file.thumbnails.medium)
57 return grid_item(
58 title="",
59 meta_text=f"<p><i class='fas fa-heart me-2'></i>{photo.num_likes}</p>",
60 url=photo.file.url,
61 image_url=image_url,
62 class_name=class_name,
63 anchor_attrs=anchor_attrs,
64 )
67@register.inclusion_tag("includes/grid_item.html")
68def liked_photo_card(photo):
69 card = photo_card(photo)
70 card.update({"meta_text": ""})
71 return card