partner_cards.py 2.24 KB
Newer Older
1
from django import template
2
from django.conf import settings
3
4
5
6
from django.template.defaultfilters import striptags, truncatechars

from thaliawebsite.templatetags.bleach_tags import bleach
from thaliawebsite.templatetags.grid_item import grid_item
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
7
from utils.media.services import get_thumbnail_url
8
9
10
11
12
13
14
15

register = template.Library()


@register.inclusion_tag('includes/grid_item.html')
def partner_card(partner):
    image_url = ''
    if partner.logo:
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
16
17
18
        image_url = get_thumbnail_url(partner.logo,
                                      settings.THUMBNAIL_SIZES['medium'],
                                      fit=False)
19

20
    meta_text = truncatechars(bleach(striptags(partner.company_profile)), 80)
21
22
23

    return grid_item(
        title=partner.name,
24
        meta_text='<p class="px-2 d-none d-md-block">{}</p>'.format(meta_text),
25
26
27
28
        url=partner.get_absolute_url,
        image_url=image_url,
        class_name='partner-card',
    )
29
30
31
32
33


@register.inclusion_tag('includes/grid_item.html')
def partner_image_card(image):
    class_name = 'partner-image-card'
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
34
    image_url = get_thumbnail_url(image, settings.THUMBNAIL_SIZES['medium'])
35
36
37

    return grid_item(
        title='',
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
38
39
        url=get_thumbnail_url(image, settings.THUMBNAIL_SIZES['large'],
                              fit=False),
40
41
        image_url=image_url,
        class_name=class_name,
42
        anchor_attrs='data-fancybox="gallery"'
43
    )
44
45
46
47


@register.inclusion_tag('partners/vacancy_card.html')
def vacancy_card(vacancy):
48
49
    image_url = None
    if vacancy.get_company_logo():
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
50
51
52
        image_url = get_thumbnail_url(vacancy.get_company_logo(),
                                      settings.THUMBNAIL_SIZES['medium'],
                                      fit=False)
53
54
55
56
57

    description = truncatechars(bleach(striptags(vacancy.description)), 150)
    extra_class = 'external-vacancy'
    url = '#vacancy-{}'.format(vacancy.id)
    if vacancy.partner:
Sébastiaan Versteeg's avatar
Sébastiaan Versteeg committed
58
59
        url = '{}#vacancy-{}'.format(vacancy.partner.get_absolute_url(),
                                     vacancy.id)
60
61
62
63
64
65
66
67
68
69
        extra_class = ''

    return {
        'title': vacancy.title,
        'company_name': vacancy.get_company_name(),
        'image_url': image_url,
        'description': description,
        'url': url,
        'extra_class': extra_class,
    }