Coverage for CIResults/admin.py: 100%
143 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 09:20 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 09:20 +0000
1from django.contrib import admin
2from django.forms import ModelForm, ModelMultipleChoiceField, PasswordInput
3from django.contrib.admin.widgets import FilteredSelectMultiple
4from django.contrib.auth.admin import UserAdmin as BaseUserModel
5from .models import BugTracker, Bug, Component, Build, Test, Machine, RunConfigTag, RunConfig, TestSuite, TestsuiteRun
6from .models import TextStatus, TestResult, IssueFilter, IssueFilterAssociated, Issue, KnownFailure, UnknownFailure
7from .models import RunFilterStatistic, MachineTag, BugTrackerSLA, BugTrackerAccount, Person, BugComment
8from .models import ReplicationScript, User
11@admin.register(ReplicationScript)
12class ReplicationScriptModel(admin.ModelAdmin):
13 list_display = ['name']
16class BugTrackerForm(ModelForm):
17 class Meta:
18 model = BugTracker
19 exclude = []
20 widgets = {
21 "password": PasswordInput(),
22 }
25@admin.register(BugTracker)
26class BugTrackerModel(admin.ModelAdmin):
27 list_display = ('name', 'public')
28 search_fields = ['name']
29 readonly_fields = ['polled']
30 form = BugTrackerForm
33@admin.register(Bug)
34class BugModel(admin.ModelAdmin):
35 readonly_fields = ['title', 'created', 'updated', 'polled', 'creator', 'product',
36 'assignee', 'component', 'features', 'platforms', 'status', 'priority',
37 'severity', 'tags', 'parent']
38 search_fields = ['bug_id']
41@admin.register(BugTrackerSLA)
42class BugTrackerSLAModel(admin.ModelAdmin):
43 list_display = ('tracker', 'priority', 'SLA')
44 search_fields = ('tracker__name', 'priority', 'SLA')
47@admin.register(Person)
48class PersonModel(admin.ModelAdmin):
49 list_display = ('full_name', 'email')
50 search_fields = ('full_name', 'email')
53@admin.register(BugTrackerAccount)
54class BugTrackerAccountModel(admin.ModelAdmin):
55 list_display = ('tracker', 'person', 'user_id')
56 search_fields = ('tracker__name', 'person__email', 'person__full_name', 'user_id')
59@admin.register(BugComment)
60class BugCommentModel(admin.ModelAdmin):
61 list_display = ('bug', 'account', 'url', 'created_on')
62 search_fields = ('bug__tracker__short_name', 'bug__bug_id', 'bug__title',
63 'account__person__full_name', 'account__person__email',
64 'url', 'created_on')
67@admin.register(Component)
68class ComponentModel(admin.ModelAdmin):
69 list_display = ('name', 'public')
70 search_fields = ['name']
73@admin.register(Build)
74class BuildModel(admin.ModelAdmin):
75 readonly_fields = ['added_on']
76 list_display = ['name']
77 search_fields = ['name', 'version', 'branch', 'repo']
78 autocomplete_fields = ['parents']
81@admin.register(Test)
82class TestModel(admin.ModelAdmin):
83 readonly_fields = ['added_on']
84 list_display = ('name', 'testsuite', 'public', 'vetted_on')
85 search_fields = ['name']
88@admin.register(MachineTag)
89class MachineTagModel(admin.ModelAdmin):
90 readonly_fields = ['added_on']
91 list_display = ('name', 'public')
92 search_fields = ['name', 'description']
95@admin.register(Machine)
96class MachineModel(admin.ModelAdmin):
97 readonly_fields = ['added_on']
98 list_display = ('name', 'public', 'vetted_on')
99 search_fields = ['name', 'description']
102@admin.register(RunConfigTag)
103class RunConfigTagModel(admin.ModelAdmin):
104 list_display = ('name', 'public')
105 search_fields = ['name', 'description']
108@admin.register(RunConfig)
109class RunModel(admin.ModelAdmin):
110 readonly_fields = ['added_on']
111 list_display = ['name']
112 search_fields = ['name', 'tags__name']
113 filter_horizontal = ['tags', 'builds']
114 list_filter = ('added_on', 'temporary')
117@admin.register(TestSuite)
118class TestSuiteModel(admin.ModelAdmin):
119 list_display = ('__str__', 'public', 'vetted_on')
120 search_fields = ['name', 'description']
121 filter_horizontal = ['acceptable_statuses']
124@admin.register(TestsuiteRun)
125class TestsuiteRunModel(admin.ModelAdmin):
126 list_display = ('runconfig', 'machine', 'run_id')
127 search_fields = ['runconfig__name', 'machine__name', 'run_id']
130@admin.register(TextStatus)
131class TextStatusModel(admin.ModelAdmin):
132 list_display = ('__str__', 'testsuite', 'vetted_on', 'severity')
135@admin.register(TestResult)
136class TestResultdModel(admin.ModelAdmin):
137 readonly_fields = ['test', 'ts_run', 'status', 'command', 'stdout', 'stderr', 'dmesg']
138 list_select_related = ['test', 'ts_run__runconfig', 'ts_run__machine']
139 show_full_result_count = False
142class IssueFilterForm(ModelForm):
143 class Meta:
144 model = IssueFilter
145 exclude = []
146 tests = ModelMultipleChoiceField(queryset=Test.objects.prefetch_related('testsuite').all(),
147 help_text="The result's machine should be one of these tests "
148 "(leave empty to ignore tests)",
149 widget=FilteredSelectMultiple('tests', False))
150 statuses = ModelMultipleChoiceField(queryset=TextStatus.objects.prefetch_related('testsuite').all(),
151 help_text="The result's status should be one of these "
152 "(leave empty to ignore results)",
153 widget=FilteredSelectMultiple('statuses', False))
156@admin.register(IssueFilter)
157class IssueFilterModel(admin.ModelAdmin):
158 readonly_fields = ['added_on']
159 filter_horizontal = ['machines', 'tests', 'statuses', 'tags']
160 form = IssueFilterForm
162 # Prevent deletion/modification, as we want data from
163 def has_delete_permission(self, request, obj=None):
164 return False # pragma: no cover
167@admin.register(IssueFilterAssociated)
168class IssueFilterAssociatedModel(admin.ModelAdmin):
169 readonly_fields = ['added_on']
170 raw_id_fields = ['filter', 'issue']
171 list_select_related = ['filter', 'issue']
172 show_full_result_count = False
175class FilterInline(admin.TabularInline):
176 readonly_fields = ['added_on']
177 model = IssueFilterAssociated
178 extra = 1
181@admin.register(Issue)
182class IssueModel(admin.ModelAdmin):
183 readonly_fields = ['added_on']
184 inlines = [FilterInline]
187@admin.register(KnownFailure)
188class KnownFailureModel(admin.ModelAdmin):
189 raw_id_fields = ['result', 'matched_ifa']
190 list_select_related = ['result__test', 'result__ts_run__runconfig', 'result__ts_run__machine', "result__status"]
191 show_full_result_count = False
194@admin.register(UnknownFailure)
195class UnknownFailureModel(admin.ModelAdmin):
196 raw_id_fields = ['result']
197 list_select_related = ['result__test', 'result__ts_run__runconfig', 'result__ts_run__machine', 'result__status']
198 show_full_result_count = False
201@admin.register(RunFilterStatistic)
202class RunFilterStatisticModel(admin.ModelAdmin):
203 list_display = ('__str__', 'covered_count', 'matched_count')
204 raw_id_fields = ['filter', 'runconfig']
205 list_select_related = ['runconfig', 'filter']
208@admin.register(User)
209class UserModel(BaseUserModel):
210 # The default admin model for User needs to be unregistered, before registering new functionalities
211 admin.site.unregister(User)
213 class UserTypeFilter(admin.SimpleListFilter):
214 title = 'user type'
215 parameter_name = "user_type"
217 def lookups(self, request, model_admin): # pragma: nocover
218 return [
219 ('is_normal_user', 'Normal user'),
220 ('is_staff', 'Staff member'),
221 ]
223 def queryset(self, request, queryset): # pragma: nocover
224 if self.value() == 'is_normal_user':
225 return queryset.filter(is_staff__exact=False, is_superuser__exact=False)
226 if self.value() == 'is_staff':
227 return queryset.filter(is_staff__exact=True)
229 list_filter = [UserTypeFilter, 'last_login']