Skip to content

Commit

Permalink
make templates more configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Nov 26, 2024
1 parent a38d24e commit b508ec5
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/django_celery_boost/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@


class CeleryTaskModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
change_form_template = "admin/celery_boost/change_form.html"
change_form_template = None
terminate_template = None
inspect_template = None
queue_template = None

def get_readonly_fields(self, request: HttpRequest, obj: "Optional[Model]" = None) -> Sequence[str]:
ret = list(super().get_readonly_fields(request, obj))
Expand Down Expand Up @@ -56,14 +59,15 @@ def doit(request: "HttpRequest") -> HttpResponseRedirect:
self,
request,
doit,
"Do you really want to queue this task?",
"Queued",
"Do you really want to terminate this task?",
"Terminated",
extra_context=ctx,
description="",
template=[
"admin/%s/%s/queue.html" % (self.opts.app_label, self.opts.model_name),
"admin/%s/queue.html" % self.opts.app_label,
"admin/celery_boost/queue.html",
self.terminate_template,
"%s/%s/%s/terminate.html" % (self.admin_site.name, self.opts.app_label, self.opts.model_name),
"%s/%s/terminate.html" % (self.admin_site.name, self.opts.app_label),
"%s/celery_boost/terminate.html" % self.admin_site.name,
],
)

Expand All @@ -72,10 +76,10 @@ def celery_inspect(self, request: HttpRequest, pk: str) -> HttpResponse:
ctx = self.get_common_context(request, pk, title="Inspect Task")
return render(
request,
[
"admin/%s/%s/inspect.html" % (self.opts.app_label, self.opts.model_name),
"admin/%s/inspect.html" % self.opts.app_label,
"admin/celery_boost/inspect.html",
self.inspect_template or [
"%s/%s/%s/inspect.html" % (self.admin_site.name, self.opts.app_label, self.opts.model_name),
"%s/%s/inspect.html" % (self.admin_site.name, self.opts.app_label),
"%s/celery_boost/inspect.html" % self.admin_site.name,
],
ctx,
)
Expand All @@ -94,7 +98,7 @@ def celery_queue(self, request: "HttpRequest", pk: str) -> "HttpResponse": # ty
def doit(request: "HttpRequest") -> HttpResponseRedirect:
obj.queue()
redirect_url = reverse(
"admin:%s_%s_change" % (obj._meta.app_label, obj._meta.model_name),
"%s:%s_%s_change" % (self.admin_site.name, obj._meta.app_label, obj._meta.model_name),
args=(obj.pk,),
current_app=self.admin_site.name,
)
Expand All @@ -108,10 +112,11 @@ def doit(request: "HttpRequest") -> HttpResponseRedirect:
"Queued",
extra_context=ctx,
description="",
template=[
"admin/%s/%s/queue.html" % (self.opts.app_label, self.opts.model_name),
"admin/%s/queue.html" % self.opts.app_label,
"admin/celery_boost/queue.html",
template=self.queue_template or [

"%s/%s/%s/queue.html" % (self.admin_site.name, self.opts.app_label, self.opts.model_name),
"%s/%s/queue.html" % (self.admin_site.name, self.opts.app_label),
"%s/celery_boost/queue.html" % self.admin_site.name,
],
)

Expand All @@ -125,7 +130,7 @@ def celery_revoke(self, request: "HttpRequest", pk: str) -> "HttpResponse": # t
def doit(request: "HttpRequest") -> HttpResponseRedirect:
obj.revoke()
redirect_url = reverse(
"admin:%s_%s_change" % (obj._meta.app_label, obj._meta.model_name),
"%s:%s_%s_change" % (self.admin_site.name, obj._meta.app_label, obj._meta.model_name),
args=(obj.pk,),
current_app=self.admin_site.name,
)
Expand All @@ -140,8 +145,8 @@ def doit(request: "HttpRequest") -> HttpResponseRedirect:
extra_context=ctx,
description="",
template=[
"admin/%s/%s/queue.html" % (self.opts.app_label, self.opts.model_name),
"admin/%s/queue.html" % self.opts.app_label,
"admin/celery_boost/queue.html",
"%s/%s/%s/queue.html" % (self.admin_site.name, self.opts.app_label, self.opts.model_name),
"%s/%s/queue.html" % (self.admin_site.name, self.opts.app_label),
"%s/celery_boost/queue.html" % self.admin_site.name,
],
)

0 comments on commit b508ec5

Please sign in to comment.