2020-02-29 10:39:42 +00:00
|
|
|
# Copyright (C) 2020 by BDE ENS Paris-Saclay
|
|
|
|
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
2020-02-29 11:32:24 +00:00
|
|
|
from .models import Reward
|
|
|
|
|
2020-02-29 10:39:42 +00:00
|
|
|
|
|
|
|
class TombolaView(TemplateView):
|
|
|
|
template_name = "tombola.html"
|
2020-02-29 10:57:19 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data()
|
|
|
|
|
2020-02-29 12:11:11 +00:00
|
|
|
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()
|
2020-02-29 11:32:24 +00:00
|
|
|
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()
|
|
|
|
|
2020-02-29 10:57:19 +00:00
|
|
|
return context
|