thabloid_cards.py 1.14 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
from django import template
from django.urls import reverse

from thaliawebsite.templatetags.grid_item import grid_item
from utils.templatetags.thumbnail import thumbnail

register = template.Library()


@register.inclusion_tag('includes/grid_item.html')
def thabloid_card(year, thabloid):
12
13
    class_name = 'year-older'
    if thabloid.year >= year - 3:
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        class_name = 'year-{}'.format(thabloid.year)

    view_url = reverse('thabloid:pages', args=[thabloid.year, thabloid.issue])
    buttons = (
        '<div class="text-center mt-2">'
        '<a href="{}" class="btn btn-secondary d-inline-flex open mr-1">'
        '<i class="fas fa-book-open"></i>'
        '</a>'
        '<a href="{}" class="btn btn-secondary d-inline-flex download ml-1">'
        '<i class="fas fa-download"></i>'
        '</a>'
        '</div>'
    ).format(view_url, thabloid.file.url)

    return grid_item(
        title='{}-{}, #{}'.format(
            thabloid.year, thabloid.year + 1, thabloid.issue
        ),
        meta_text=buttons,
        url=None,
        image_url=thumbnail(thabloid.cover, '255x360'),
        class_name='thabloid-card mix {}'.format(class_name),
    )