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

51 lines
1.4 KiB
Python
Raw Normal View History

2021-10-03 16:44:54 +02:00
# 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
2022-06-19 16:03:59 +02:00
from utils.views import JSONResponseMixin
2021-10-03 16:44:54 +02:00
def list_faction_redirect(request, *args, **kwargs):
first_faction: Faction = Faction.objects.first()
if not first_faction:
return redirect("factionadd")
return redirect(first_faction)
2022-06-19 16:03:59 +02:00
class FactionDetailView(JSONResponseMixin, generic.DetailView):
2021-10-15 21:47:49 +02:00
template_name = "factions/detail.jinja"
2021-10-03 16:44:54 +02:00
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):
2021-10-15 21:47:49 +02:00
template_name = "loot/edit.jinja"
2021-10-03 16:44:54 +02:00
model = Faction
form_class = FactionForm
context_object_name = "object"
class FactionEditView(generic.UpdateView):
2021-10-15 21:47:49 +02:00
template_name = "loot/edit.jinja"
2021-10-03 16:44:54 +02:00
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):
2021-10-15 21:47:49 +02:00
template_name = "common/confirm_delete.jinja"
2021-10-03 16:44:54 +02:00
model = Faction
success_url = reverse_lazy('factionlist')