2023-08-25 19:50:09 +00:00
|
|
|
from django.views.generic import ListView, DetailView
|
2023-06-11 18:01:36 +00:00
|
|
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
2023-06-10 20:32:45 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
|
|
|
|
from guild.models import Adventure, PlaySession
|
|
|
|
|
|
|
|
|
2023-06-11 19:20:45 +00:00
|
|
|
class AdventureListView(LoginRequiredMixin, ListView):
|
|
|
|
model = Adventure
|
|
|
|
context_object_name = "adventures"
|
|
|
|
|
2023-06-11 19:25:30 +00:00
|
|
|
|
2023-06-10 20:32:45 +00:00
|
|
|
class CreateAdventureView(LoginRequiredMixin, CreateView):
|
|
|
|
model = Adventure
|
|
|
|
fields = ["name", "description", "master"]
|
|
|
|
|
2023-06-11 19:25:30 +00:00
|
|
|
|
2023-06-10 20:32:45 +00:00
|
|
|
class AdventureDetailView(LoginRequiredMixin, DetailView):
|
|
|
|
model = Adventure
|
|
|
|
|
2023-06-13 20:09:25 +00:00
|
|
|
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
|
|
|
|
|
2023-06-11 19:25:30 +00:00
|
|
|
|
2023-06-11 18:01:36 +00:00
|
|
|
class AdventureUpdateView(LoginRequiredMixin, UpdateView):
|
|
|
|
model = Adventure
|
|
|
|
fields = ["name", "description", "master"]
|
|
|
|
|
2023-06-11 19:25:30 +00:00
|
|
|
|
2023-06-11 18:01:36 +00:00
|
|
|
class AdventureDeleteView(LoginRequiredMixin, DeleteView):
|
|
|
|
model = Adventure
|
|
|
|
success_url = "/"
|