[v2,06/10] admin: Add label views

Message ID 20181014124541.13393-7-stephen@that.guru
State New
Headers show
Series
  • Add labels support
Related show

Commit Message

Stephen Finucane Oct. 14, 2018, 12:45 p.m.
There are two added: a general labels view that includes both project
and non-project labels, and an inline labels view that's part of the
project.

Signed-off-by: Stephen Finucane <stephen@that.guru>
---
v2:
- Only show labels that are not associated with a project for the label
  admin view
- Add 'project' to list view
---
 patchwork/admin.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Patch

diff --git a/patchwork/admin.py b/patchwork/admin.py
index 0e9ccfa7..31103106 100644
--- a/patchwork/admin.py
+++ b/patchwork/admin.py
@@ -12,6 +12,7 @@  from patchwork.models import Check
 from patchwork.models import Comment
 from patchwork.models import CoverLetter
 from patchwork.models import DelegationRule
+from patchwork.models import Label
 from patchwork.models import Patch
 from patchwork.models import Person
 from patchwork.models import Project
@@ -38,10 +39,16 @@  class DelegationRuleInline(admin.TabularInline):
     fields = ('path', 'user', 'priority')
 
 
+class LabelInline(admin.TabularInline):
+    model = Label
+    fields = ('name', 'description', 'color')
+
+
 class ProjectAdmin(admin.ModelAdmin):
     list_display = ('name', 'linkname', 'listid', 'listemail')
     inlines = [
         DelegationRuleInline,
+        LabelInline,
     ]
 
 
@@ -71,6 +78,7 @@  class SubmissionAdmin(admin.ModelAdmin):
 class PatchAdmin(admin.ModelAdmin):
     list_display = ('name', 'submitter', 'project', 'state', 'date',
                     'archived', 'is_pull_request')
+    readonly_fields = ('labels',)
     list_filter = ('project', 'state', 'archived')
     list_select_related = ('submitter', 'project', 'state')
     search_fields = ('name', 'submitter__name', 'submitter__email')
@@ -134,6 +142,14 @@  class TagAdmin(admin.ModelAdmin):
     list_display = ('name',)
 
 
+class LabelAdmin(admin.ModelAdmin):
+    list_display = ('name', 'color')
+
+    def get_queryset(self, request):
+        qs = super(LabelAdmin, self).get_queryset(request)
+        return qs.filter(project=None)
+
+
 admin.site.unregister(User)
 admin.site.register(User, UserAdmin)
 admin.site.register(Project, ProjectAdmin)
@@ -148,3 +164,4 @@  admin.site.register(SeriesReference, SeriesReferenceAdmin)
 admin.site.register(Check, CheckAdmin)
 admin.site.register(Bundle, BundleAdmin)
 admin.site.register(Tag, TagAdmin)
+admin.site.register(Label, LabelAdmin)