Use CRUD helper for position list
This commit is contained in:
@@ -33,7 +33,7 @@ class RestrictedViewMixin:
|
||||
page_kwarg = "page"
|
||||
ordering = None
|
||||
|
||||
def get_queryset(self):
|
||||
def get_queryset(self, **kwargs):
|
||||
"""
|
||||
This function is overriden to filter the objects by the requesting user.
|
||||
"""
|
||||
@@ -70,15 +70,19 @@ class RestrictedViewMixin:
|
||||
|
||||
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
|
||||
if self.model is None:
|
||||
self.title = self.context_object_name.title()
|
||||
self.title_singular = self.context_object_name_singular.title()
|
||||
else:
|
||||
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
|
||||
|
||||
self.context_object_name = self.context_object_name.replace(" ", "")
|
||||
self.context_object_name_singular = self.context_object_name_singular.replace(
|
||||
" ", ""
|
||||
)
|
||||
self.context_object_name = self.context_object_name.replace(" ", "")
|
||||
self.context_object_name_singular = (
|
||||
self.context_object_name_singular.replace(" ", "")
|
||||
)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -97,11 +101,13 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView):
|
||||
submit_url_name = None
|
||||
|
||||
delete_all_url_name = None
|
||||
widget_options = None
|
||||
|
||||
# copied from BaseListView
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.request = request
|
||||
self.object_list = self.get_queryset()
|
||||
self.object_list = self.get_queryset(**kwargs)
|
||||
print("OBJ , ", self.object_list)
|
||||
allow_empty = self.get_allow_empty()
|
||||
|
||||
type = kwargs.get("type", None)
|
||||
@@ -132,9 +138,7 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView):
|
||||
is_empty = not self.object_list
|
||||
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
|
||||
@@ -144,12 +148,19 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView):
|
||||
context["page_title"] = self.page_title
|
||||
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
|
||||
|
||||
if self.submit_url_name is not None:
|
||||
context["submit_url"] = reverse(self.submit_url_name, kwargs={"type": type})
|
||||
|
||||
if self.list_url_name is not None:
|
||||
context["list_url"] = reverse(self.list_url_name, kwargs=list_url_args)
|
||||
|
||||
if self.delete_all_url_name:
|
||||
context["delete_all_url"] = reverse(self.delete_all_url_name)
|
||||
if self.widget_options:
|
||||
context["widget_options"] = self.widget_options
|
||||
|
||||
# Return partials for HTMX
|
||||
if self.request.htmx:
|
||||
|
||||
Reference in New Issue
Block a user