Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved display of TaskModel hierarchy in TaskModelAdmin object page #142

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions huey_monitor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TaskModelAdmin(FixLookupAllowedMixin, admin.ModelAdmin):
def get_changelist(self, request, **kwargs):
return TaskModelChangeList

@admin.display(description=_('Execution detail'))
def column_name(self, obj):
qs = obj.sub_tasks.all()
context = {
Expand All @@ -77,18 +78,14 @@ def column_name(self, obj):
column_name.short_description = _('Task name')

def task_hierarchy_info(self, obj):
qs = TaskModel.objects.filter(parent_task_id=obj.pk).order_by('create_dt')
context = {
'sub_tasks': qs
}
if obj.parent_task_id is not None:
# This is a sub task
context = {
'main_task': TaskModel.objects.get(pk=obj.parent_task_id),
}
else:
# This is a main Task
qs = TaskModel.objects.filter(parent_task_id=obj.pk)
context = {
'sub_tasks': qs,
}

context['main_task'] = TaskModel.objects.get(pk=obj.parent_task_id)

return render_to_string(
template_name='admin/huey_monitor/taskmodel/task_hierarchy_info.html',
context=context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{% load i18n humanize_time %}

{% if main_task %}
<p>Parent task: </p>
<p>
<a href="{{ main_task.admin_link }}">{% firstof main_task.desc main_task.name %}</a>
{{ main_task.state|default_if_none:"" }}
{{ main_task.human_progress_string }}
</p>
{% elif sub_tasks %}
{% else %}
<p>This task has no parent task.</p>
{% endif %}
<br>
{% if sub_tasks %}
<p>This task has {{sub_tasks|length}} sub tasks:</p>
<table class="table-bordered table-condensed table-striped huey_monitor">
<thead>
<tr>
Expand Down
Loading