1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/locations/views.py

51 lines
1.4 KiB
Python
Raw Permalink Normal View History

2021-09-06 20:34:43 +02:00
# Create your views here.
2021-09-15 16:51:43 +02:00
from django.shortcuts import redirect
2021-09-29 22:06:11 +02:00
from django.urls import reverse_lazy
2021-09-15 16:51:43 +02:00
from django.views import generic
from locations.forms import LocationForm
from locations.models import Location
2022-06-19 16:03:59 +02:00
from utils.views import JSONResponseMixin
2021-09-15 16:51:43 +02:00
def list_location_redirect(request, *args, **kwargs):
first_location: Location = Location.objects.first()
if not first_location:
return redirect("locationadd")
return redirect(first_location)
2022-06-19 16:03:59 +02:00
class LocationDetailView(JSONResponseMixin, generic.DetailView):
2021-10-15 21:47:49 +02:00
template_name = "locations/detail.jinja"
2021-09-15 16:51:43 +02:00
model = Location
context_object_name = "location"
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data["roots"] = Location.objects.with_tree_fields()
return data
class LocationCreateView(generic.CreateView):
2021-10-15 21:47:49 +02:00
template_name = "loot/edit.jinja"
2021-09-15 16:51:43 +02:00
model = Location
form_class = LocationForm
context_object_name = "object"
class LocationEditView(generic.UpdateView):
2021-10-15 21:47:49 +02:00
template_name = "loot/edit.jinja"
2021-09-15 16:51:43 +02:00
model = Location
form_class = LocationForm
def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs)
data['edit'] = True
return data
2021-09-29 22:06:11 +02:00
class LocationDeleteView(generic.DeleteView):
2021-10-15 21:47:49 +02:00
template_name = "common/confirm_delete.jinja"
2021-09-29 22:06:11 +02:00
model = Location
success_url = reverse_lazy('locationlist')