Simplify DB object management with Django CRUD helpers
This commit is contained in:
@@ -18,17 +18,19 @@ def get_callbacks(user, hook=None):
|
||||
|
||||
class Callbacks(LoginRequiredMixin, View):
|
||||
allowed_types = ["modal", "widget", "window", "page"]
|
||||
window_content = "window-content/callbacks.html"
|
||||
window_content = "window-content/objects.html"
|
||||
list_template = "partials/callback-list.html"
|
||||
page_title = "List of received callbacks"
|
||||
|
||||
async def get(self, request, type, hook_id=None):
|
||||
async def get(self, request, type, pk=None):
|
||||
if type not in self.allowed_types:
|
||||
return HttpResponseBadRequest
|
||||
template_name = f"wm/{type}.html"
|
||||
unique = str(uuid.uuid4())[:8]
|
||||
|
||||
if hook_id:
|
||||
if pk:
|
||||
try:
|
||||
hook = Hook.objects.get(id=hook_id, user=request.user)
|
||||
hook = Hook.objects.get(id=pk, user=request.user)
|
||||
except Hook.DoesNotExist:
|
||||
message = "Hook does not exist."
|
||||
message_class = "danger"
|
||||
@@ -48,7 +50,9 @@ class Callbacks(LoginRequiredMixin, View):
|
||||
"title": f"Callbacks ({type})",
|
||||
"unique": unique,
|
||||
"window_content": self.window_content,
|
||||
"items": callbacks,
|
||||
"list_template": self.list_template,
|
||||
"object_list": callbacks,
|
||||
"type": type,
|
||||
"page_title": self.page_title,
|
||||
}
|
||||
return render(request, template_name, context)
|
||||
|
||||
Reference in New Issue
Block a user