# Copyright (C) 2020 by BDE ENS Paris-Saclay from django.views.generic import TemplateView from .models import Reward class TombolaView(TemplateView): template_name = "tombola.html" def get_context_data(self, **kwargs): context = super().get_context_data() next_rewards = Reward.objects.filter(rewarded_by__isnull=True).order_by('order').reverse() old_reward = Reward.objects.filter(rewarded_by__isnull=False).order_by('order').reverse() context['old_rewards'] = old_reward.all() if old_reward.exists(): context['previous_reward'] = old_reward.last() context['next_rewards'] = next_rewards.all() if next_rewards.exists(): context['current_reward'] = next_rewards.first() return context