partner_cards.py 2.12 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
7
from utils.templatetags.thumbnail import thumbnail
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:
16
17
        image_url = thumbnail(partner.logo, settings.THUMBNAIL_SIZES['medium'],
                              fit=False)
18

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

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


@register.inclusion_tag('includes/grid_item.html')
def partner_image_card(image):
    class_name = 'partner-image-card'
33
    image_url = thumbnail(image, settings.THUMBNAIL_SIZES['medium'])
34
35
36
37
38
39

    return grid_item(
        title='',
        url=thumbnail(image, settings.THUMBNAIL_SIZES['large'], fit=False),
        image_url=image_url,
        class_name=class_name,
40
        anchor_attrs='data-fancybox="gallery"'
41
    )
42
43
44
45


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

    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
56
57
        url = '{}#vacancy-{}'.format(vacancy.partner.get_absolute_url(),
                                     vacancy.id)
58
59
60
61
62
63
64
65
66
67
        extra_class = ''

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