guild-journal/guild/views/__init__.py

25 lines
875 B
Python
Raw Normal View History

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-11 18:37:03 +00:00
from guild.models import Adventure, Character, Player
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-11 18:01:36 +00:00
return context