views.py 1.05 KB
Newer Older
Luuk Scholten's avatar
Luuk Scholten committed
1
from django.shortcuts import get_object_or_404, render
2

3
from partners.models import Partner, Vacancy, VacancyCategory
4
5
6
7
8
from random import random


def index(request):
    partners = Partner.objects.filter(is_active=True, is_main_partner=False)
9
    try:
10
        main_partner = Partner.objects.get(
11
12
            is_active=True,
            is_main_partner=True
13
        )
14
15
    except Partner.DoesNotExist:
        main_partner = None
16
17
18

    context = {
        'main_partner': main_partner,
19
20
21
        'partners': sorted(partners, key=lambda x: random()),
    }
    return render(request, 'partners/index.html', context)
Luuk Scholten's avatar
Luuk Scholten committed
22
23
24
25


def partner(request, slug):
    partner = get_object_or_404(Partner, slug=slug)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    context = {
        'partner': partner,
        'vacancies': Vacancy.objects.filter(partner=partner),
    }
    return render(request, 'partners/partner.html', context)


def vacancies(request):
    context = {
        'vacancies': Vacancy.objects.all(),
        'categories': VacancyCategory.objects.all(),
    }

    return render(request, 'partners/vacancies.html', context)