Skip to content

Commit

Permalink
Display related items on workflow & workflow template admin views
Browse files Browse the repository at this point in the history
  • Loading branch information
dalecannon committed Jan 10, 2025
1 parent a89d67e commit 34d011a
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@
from tasks.models import ProgressState
from tasks.models import Task
from tasks.models import TaskAssignee
from tasks.models import TaskItem
from tasks.models import TaskItemTemplate
from tasks.models import TaskLog
from tasks.models import TaskTemplate
from tasks.models import TaskWorkflow
from tasks.models import TaskWorkflowTemplate


class ReadOnlyAdminMixin:
def has_add_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


class TaskAdminMixin:
def link_to_task(self, task: Task):
task_url = reverse(
Expand Down Expand Up @@ -50,7 +63,7 @@ def queryset(self, request, queryset):
return queryset.parents()


class TaskAdmin(TaskAdminMixin, admin.ModelAdmin):
class TaskAdmin(ReadOnlyAdminMixin, TaskAdminMixin, admin.ModelAdmin):
list_display = [
"id",
"title",
Expand Down Expand Up @@ -88,7 +101,7 @@ class ProgressStateAdmin(admin.ModelAdmin):
search_fields = ["name"]


class TaskAssigneeAdmin(TaskAdminMixin, admin.ModelAdmin):
class TaskAssigneeAdmin(ReadOnlyAdminMixin, TaskAdminMixin, admin.ModelAdmin):
list_display = ["id", "assignee", "assignment_type", "task_id", "unassigned_at"]
search_fields = ["user__username", "assignment_type", "task__id"]

Expand All @@ -104,7 +117,7 @@ def task_id(self, obj):
return self.link_to_task(obj.task)


class TaskLogAdmin(admin.ModelAdmin):
class TaskLogAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
list_display = ["task", "action", "created_at"]
list_filter = ["action"]
readonly_fields = [
Expand All @@ -117,24 +130,29 @@ class TaskLogAdmin(admin.ModelAdmin):
]


class ReadOnlyAdminMixin:
def has_add_permission(self, request):
return False

def has_change_permission(self, request, obj=None):
return False
class TaskItemTemplateInline(admin.TabularInline):
model = TaskItemTemplate
readonly_fields = ("task_template_description", "position")

def has_delete_permission(self, request, obj=None):
return False
@admin.display(description="Description")
def task_template_description(self, obj):
return obj.task_template.description


class TaskWorkflowTemplateAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
list_display = (
"id",
"title",
"description",
"task_templates_count",
"creator",
)
search_fields = ("title", "description")
inlines = [TaskItemTemplateInline]

@admin.display(description="Task templates")
def task_templates_count(self, obj):
return obj.get_task_templates().count()


class TaskTemplateAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
Expand Down Expand Up @@ -165,14 +183,29 @@ def link_to_task_workflow_template(self, task_item_template):
)


class TaskWorflowAdmin(admin.ModelAdmin):
class TaskItemInline(admin.TabularInline):
model = TaskItem
readonly_fields = ("task_description", "position")

@admin.display(description="Description")
def task_description(self, obj):
return obj.task.description


class TaskWorflowAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
search_fields = ["summary_task__title"]
list_display = [
"id",
"title",
"description",
"task_count",
"creator_template",
]
inlines = [TaskItemInline]

@admin.display(description="Tasks")
def task_count(self, obj):
return obj.get_tasks().count()


admin.site.register(Task, TaskAdmin)
Expand Down

0 comments on commit 34d011a

Please sign in to comment.