|
|
|
@ -19,12 +19,17 @@ class ObjectList(ListView):
|
|
|
|
|
|
|
|
|
|
model = None
|
|
|
|
|
context_object_name = "objects"
|
|
|
|
|
context_object_name_singular = "object"
|
|
|
|
|
page_title = None
|
|
|
|
|
page_subtitle = None
|
|
|
|
|
|
|
|
|
|
title = "Objects"
|
|
|
|
|
title_singular = "Object"
|
|
|
|
|
|
|
|
|
|
list_url_name = None
|
|
|
|
|
# WARNING: TAKEN FROM locals()
|
|
|
|
|
list_url_args = ["type"]
|
|
|
|
|
|
|
|
|
|
submit_url_name = None
|
|
|
|
|
|
|
|
|
|
# copied from BaseListView
|
|
|
|
@ -39,6 +44,12 @@ class ObjectList(ListView):
|
|
|
|
|
return HttpResponseBadRequest("Invalid type specified")
|
|
|
|
|
self.template_name = f"wm/{type}.html"
|
|
|
|
|
unique = str(uuid.uuid4())[:8]
|
|
|
|
|
|
|
|
|
|
list_url_args = {}
|
|
|
|
|
for arg in self.list_url_args:
|
|
|
|
|
list_url_args[arg] = locals()[arg]
|
|
|
|
|
print("LIST URL ARGS", list_url_args)
|
|
|
|
|
|
|
|
|
|
if type == "page":
|
|
|
|
|
type = "modal"
|
|
|
|
|
|
|
|
|
@ -55,6 +66,8 @@ class ObjectList(ListView):
|
|
|
|
|
if is_empty:
|
|
|
|
|
raise Http404("Empty list")
|
|
|
|
|
submit_url = reverse(self.submit_url_name, kwargs={"type": type})
|
|
|
|
|
|
|
|
|
|
list_url = reverse(self.list_url_name, kwargs=list_url_args)
|
|
|
|
|
context = self.get_context_data()
|
|
|
|
|
context["title"] = self.title + f" ({type})"
|
|
|
|
|
context["title_singular"] = self.title_singular
|
|
|
|
@ -65,6 +78,13 @@ class ObjectList(ListView):
|
|
|
|
|
context["page_subtitle"] = self.page_subtitle
|
|
|
|
|
context["type"] = type
|
|
|
|
|
context["submit_url"] = submit_url
|
|
|
|
|
context["list_url"] = list_url
|
|
|
|
|
context["context_object_name"] = self.context_object_name
|
|
|
|
|
context["context_object_name_singular"] = self.context_object_name_singular
|
|
|
|
|
|
|
|
|
|
# Return partials for HTMX
|
|
|
|
|
if self.request.htmx:
|
|
|
|
|
self.template_name = self.list_template
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -77,6 +97,10 @@ class ObjectCreate(CreateView):
|
|
|
|
|
context_object_name = "objects"
|
|
|
|
|
submit_url_name = None
|
|
|
|
|
|
|
|
|
|
list_url_name = None
|
|
|
|
|
# WARNING: TAKEN FROM locals()
|
|
|
|
|
list_url_args = ["type"]
|
|
|
|
|
|
|
|
|
|
request = None
|
|
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
@ -87,7 +111,9 @@ class ObjectCreate(CreateView):
|
|
|
|
|
obj.save()
|
|
|
|
|
form.save_m2m()
|
|
|
|
|
context = {"message": "Object created", "class": "success"}
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
|
response = self.render_to_response(context)
|
|
|
|
|
response["HX-Trigger"] = f"{self.context_object_name_singular}Event"
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
self.request = request
|
|
|
|
@ -98,16 +124,26 @@ class ObjectCreate(CreateView):
|
|
|
|
|
return HttpResponseBadRequest("Invalid type specified")
|
|
|
|
|
self.template_name = f"wm/{type}.html"
|
|
|
|
|
unique = str(uuid.uuid4())[:8]
|
|
|
|
|
|
|
|
|
|
list_url_args = {}
|
|
|
|
|
for arg in self.list_url_args:
|
|
|
|
|
list_url_args[arg] = locals()[arg]
|
|
|
|
|
print("LIST URL ARGS", list_url_args)
|
|
|
|
|
|
|
|
|
|
if type == "page":
|
|
|
|
|
type = "modal"
|
|
|
|
|
|
|
|
|
|
self.object = None
|
|
|
|
|
submit_url = reverse(self.submit_url_name, kwargs={"type": type})
|
|
|
|
|
|
|
|
|
|
list_url = reverse(self.list_url_name, kwargs=list_url_args)
|
|
|
|
|
context = self.get_context_data()
|
|
|
|
|
context["unique"] = unique
|
|
|
|
|
context["window_content"] = self.window_content
|
|
|
|
|
context["context_object_name"] = self.context_object_name
|
|
|
|
|
context["context_object_name_singular"] = self.context_object_name_singular
|
|
|
|
|
context["submit_url"] = submit_url
|
|
|
|
|
context["list_url"] = list_url
|
|
|
|
|
context["type"] = type
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
|
|
|
|
|
@ -143,7 +179,9 @@ class ObjectUpdate(UpdateView):
|
|
|
|
|
obj.save()
|
|
|
|
|
form.save_m2m()
|
|
|
|
|
context = {"message": "Object updated", "class": "success"}
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
|
response = self.render_to_response(context)
|
|
|
|
|
response["HX-Trigger"] = f"{self.context_object_name_singular}Event"
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
self.request = request
|
|
|
|
@ -166,6 +204,7 @@ class ObjectUpdate(UpdateView):
|
|
|
|
|
context["unique"] = unique
|
|
|
|
|
context["window_content"] = self.window_content
|
|
|
|
|
context["context_object_name"] = self.context_object_name
|
|
|
|
|
context["context_object_name_singular"] = self.context_object_name_singular
|
|
|
|
|
context["submit_url"] = submit_url
|
|
|
|
|
context["type"] = type
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
@ -178,6 +217,7 @@ class ObjectUpdate(UpdateView):
|
|
|
|
|
|
|
|
|
|
class ObjectDelete(DeleteView):
|
|
|
|
|
model = None
|
|
|
|
|
context_object_name_singular = "object"
|
|
|
|
|
template_name = "partials/notify.html"
|
|
|
|
|
|
|
|
|
|
# Overriden to prevent success URL from being used
|
|
|
|
@ -190,7 +230,9 @@ class ObjectDelete(DeleteView):
|
|
|
|
|
# success_url = self.get_success_url()
|
|
|
|
|
self.object.delete()
|
|
|
|
|
context = {"message": "Object deleted", "class": "success"}
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
|
response = self.render_to_response(context)
|
|
|
|
|
response["HX-Trigger"] = f"{self.context_object_name_singular}Event"
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
# This will be used in newer Django versions, until then we get a warning
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
@ -200,4 +242,6 @@ class ObjectDelete(DeleteView):
|
|
|
|
|
self.object = self.get_object()
|
|
|
|
|
self.object.delete()
|
|
|
|
|
context = {"message": "Object deleted", "class": "success"}
|
|
|
|
|
return self.render_to_response(context)
|
|
|
|
|
response = self.render_to_response(context)
|
|
|
|
|
response["HX-Trigger"] = f"{self.context_object_name_singular}Event"
|
|
|
|
|
return response
|
|
|
|
|