2023-06-13 20:09:25 +00:00
|
|
|
from datetime import date
|
2023-06-10 19:33:06 +00:00
|
|
|
from django.views.generic import TemplateView, ListView, DetailView
|
|
|
|
from django.views.generic.edit import CreateView
|
2023-06-09 20:19:15 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2023-06-09 19:51:18 +00:00
|
|
|
|
2023-06-20 19:22:56 +00:00
|
|
|
from guild.models import Adventure, Character, Player, Reward
|
2023-06-10 19:33:06 +00:00
|
|
|
|
2023-06-11 19:25:30 +00:00
|
|
|
|
2023-06-09 19:51:18 +00:00
|
|
|
# Create your views here.
|
2023-06-09 20:19:15 +00:00
|
|
|
class HomeView(LoginRequiredMixin, TemplateView):
|
|
|
|
template_name = "guild/home.html"
|
2023-06-10 19:33:06 +00:00
|
|
|
|
2023-06-11 18:01:36 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2023-06-13 20:09:25 +00:00
|
|
|
advs = Adventure.objects.prefetch_related("playsession_set", "master").all()
|
|
|
|
advs = sorted(
|
|
|
|
advs,
|
|
|
|
key=lambda x: x.last_session.date if x.last_session else date.min,
|
|
|
|
reverse=True,
|
|
|
|
)
|
|
|
|
context["adventures"] = advs
|
2023-06-11 18:37:03 +00:00
|
|
|
context["players"] = Player.objects.all()
|
|
|
|
context["characters"] = Character.objects.all()
|
2023-06-20 19:22:56 +00:00
|
|
|
|
|
|
|
context["rewards"] = Reward.objects.filter(character=None).order_by(
|
|
|
|
"-playsession__date"
|
|
|
|
)
|
|
|
|
context["resources"] = {}
|
|
|
|
for reward in context["rewards"]:
|
|
|
|
if reward.resource.name not in context["resources"]:
|
|
|
|
context["resources"][reward.resource.name] = 0
|
|
|
|
context["resources"][reward.resource.name] += reward.amount
|
2023-06-11 18:01:36 +00:00
|
|
|
return context
|