Pull object names from model definitions in CRUD views
This commit is contained in:
@@ -12,20 +12,23 @@ from core.util import logs
|
||||
log = logs.get_logger(__name__)
|
||||
|
||||
|
||||
class ObjectList(ListView):
|
||||
class ObjectNameMixin(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.title_singular = self.model._meta.verbose_name.title() # Hook
|
||||
self.context_object_name_singular = self.title_singular.lower() # hook
|
||||
self.title = self.model._meta.verbose_name_plural.title() # Hooks
|
||||
self.context_object_name = self.title.lower() # hooks
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class ObjectList(ObjectNameMixin, ListView):
|
||||
allowed_types = ["modal", "widget", "window", "page"]
|
||||
window_content = "window-content/objects.html"
|
||||
list_template = None
|
||||
|
||||
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"]
|
||||
@@ -91,13 +94,12 @@ class ObjectList(ListView):
|
||||
return self.render_to_response(context)
|
||||
|
||||
|
||||
class ObjectCreate(CreateView):
|
||||
class ObjectCreate(ObjectNameMixin, CreateView):
|
||||
allowed_types = ["modal", "widget", "window", "page"]
|
||||
window_content = "window-content/object-form.html"
|
||||
parser_classes = [FormParser]
|
||||
|
||||
model = None
|
||||
context_object_name = "objects"
|
||||
submit_url_name = None
|
||||
|
||||
list_url_name = None
|
||||
@@ -159,21 +161,19 @@ class ObjectCreate(CreateView):
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ObjectRead(DetailView):
|
||||
class ObjectRead(ObjectNameMixin, DetailView):
|
||||
allowed_types = ["modal", "widget", "window", "page"]
|
||||
window_content = "window-content/object.html"
|
||||
|
||||
model = None
|
||||
context_object_name = "object"
|
||||
|
||||
|
||||
class ObjectUpdate(UpdateView):
|
||||
class ObjectUpdate(ObjectNameMixin, UpdateView):
|
||||
allowed_types = ["modal", "widget", "window", "page"]
|
||||
window_content = "window-content/object-form.html"
|
||||
parser_classes = [FormParser]
|
||||
|
||||
model = None
|
||||
context_object_name = "objects"
|
||||
submit_url_name = None
|
||||
|
||||
request = None
|
||||
@@ -225,9 +225,8 @@ class ObjectUpdate(UpdateView):
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ObjectDelete(DeleteView):
|
||||
class ObjectDelete(ObjectNameMixin, DeleteView):
|
||||
model = None
|
||||
context_object_name_singular = "object"
|
||||
template_name = "partials/notify.html"
|
||||
|
||||
# Overriden to prevent success URL from being used
|
||||
|
||||
Reference in New Issue
Block a user