from django.shortcuts import render from django.views.generic import TemplateView from .models import * # Create your views here. class HomeView(TemplateView): template_name = 'home.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) posts = list(Post.objects.all()) context['home'] = 'active' context['highlight'] = posts[0] if len(posts) != 0 else None context['posts'] = posts[1:] if len(posts) > 1 else [] return context class MembershipView(TemplateView): template_name = 'membership.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['memberships'] = Membership.objects.all() return context class AdministrationView(TemplateView): template_name = 'administration.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) files = Administration.objects context = { **context, 'statut': files.filter(type=1).first(), 'ogloszenia': files.filter(type=2), 'protokoly': files.filter(type=3), 'regulaminy': files.filter(type=4) } return context