42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
from typing import Any, Dict, Optional, Type
|
|
from django.forms.models import BaseModelForm
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import get_object_or_404
|
|
from django.views.generic import TemplateView, ListView, DetailView
|
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from guild.forms import PlaySessionForm
|
|
|
|
from guild.models import Adventure, PlaySession
|
|
|
|
|
|
class AdventureListView(LoginRequiredMixin, ListView):
|
|
model = Adventure
|
|
context_object_name = "adventures"
|
|
|
|
|
|
class CreateAdventureView(LoginRequiredMixin, CreateView):
|
|
model = Adventure
|
|
fields = ["name", "description", "master"]
|
|
|
|
|
|
class AdventureDetailView(LoginRequiredMixin, DetailView):
|
|
model = Adventure
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["sessions"] = PlaySession.objects.filter(
|
|
adventure=self.object
|
|
).order_by("date")
|
|
return context
|
|
|
|
|
|
class AdventureUpdateView(LoginRequiredMixin, UpdateView):
|
|
model = Adventure
|
|
fields = ["name", "description", "master"]
|
|
|
|
|
|
class AdventureDeleteView(LoginRequiredMixin, DeleteView):
|
|
model = Adventure
|
|
success_url = "/"
|