1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/factions/views.py
2022-06-19 16:03:59 +02:00

50 lines
1.4 KiB
Python

# Create your views here.
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.views import generic
from factions.forms import FactionForm
from factions.models import Faction
from utils.views import JSONResponseMixin
def list_faction_redirect(request, *args, **kwargs):
first_faction: Faction = Faction.objects.first()
if not first_faction:
return redirect("factionadd")
return redirect(first_faction)
class FactionDetailView(JSONResponseMixin, generic.DetailView):
template_name = "factions/detail.jinja"
model = Faction
context_object_name = "faction"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data["factions"] = Faction.objects.all().select_related()
return data
class FactionCreateView(generic.CreateView):
template_name = "loot/edit.jinja"
model = Faction
form_class = FactionForm
context_object_name = "object"
class FactionEditView(generic.UpdateView):
template_name = "loot/edit.jinja"
model = Faction
form_class = FactionForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data['edit'] = True
return data
class FactionDeleteView(generic.DeleteView):
template_name = "common/confirm_delete.jinja"
model = Faction
success_url = reverse_lazy('factionlist')