• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uw-it-aca / mdot / 4703590766

pending completion
4703590766

Pull #322

github

GitHub
Merge 814c730f7 into 0e0c327d3
Pull Request #322: Task/guidelines content

20 of 20 new or added lines in 1 file covered. (100.0%)

884 of 939 relevant lines covered (94.14%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.49
/mdot/admin.py
1
# Copyright 2023 UW-IT, University of Washington
2
# SPDX-License-Identifier: Apache-2.0
3

4
from django.conf import settings
1✔
5
from django.contrib import admin
1✔
6
from .models import *
1✔
7
import logging
1✔
8

9
from uw_saml.utils import is_member_of_group
1✔
10

11

12
admin_group = settings.ADMIN_AUTHZ_GROUP
1✔
13

14
logger = logging.getLogger("filter")
1✔
15

16

17
class SAMLAdminSite(admin.AdminSite):
1✔
18
    def has_permission(self, request):
1✔
19
        return (
×
20
            is_member_of_group(request, admin_group) and request.user.is_active
21
        )
22

23
    def __init__(self, *args, **kwargs):
1✔
24
        super(SAMLAdminSite, self).__init__(*args, **kwargs)
1✔
25
        self._registry.update(admin.site._registry)
1✔
26

27

28
admin_site = SAMLAdminSite(name="SAMLAdmin")
1✔
29

30

31
class PlatformInline(admin.TabularInline):
1✔
32
    model = Platform
1✔
33
    extra = 0
1✔
34

35

36
@admin.register(Platform, site=admin_site)
1✔
37
class PlatformAdmin(admin.ModelAdmin):
1✔
38
    model = Platform
1✔
39

40

41
class SponsorInLine(admin.TabularInline):
1✔
42
    model = Sponsor
1✔
43
    extra = 0
1✔
44

45

46
@admin.register(Sponsor, site=admin_site)
1✔
47
class SponsorAdmin(admin.ModelAdmin):
1✔
48
    model = Sponsor
1✔
49
    list_display = (
1✔
50
        "full_name",
51
        "netid",
52
        "department",
53
    )
54

55

56
class ManagerInLine(admin.TabularInline):
1✔
57
    model = Manager
1✔
58
    extra = 0
1✔
59

60

61
@admin.register(Manager, site=admin_site)
1✔
62
class ManagerAdmin(admin.ModelAdmin):
1✔
63
    model = Manager
1✔
64
    list_display = (
1✔
65
        "full_name",
66
        "netid",
67
        "email",
68
    )
69
    fields = ["first_name", "last_name", "netid", "email"]
1✔
70

71

72
# filters agreements into agreed, denied, or pending
73
class AgreementFilter(admin.SimpleListFilter):
1✔
74
    title = "Agreement"
1✔
75
    parameter_name = "status"
1✔
76

77
    def lookups(self, request, model_admin):
1✔
78
        return [
1✔
79
            ("agreed", "Agreed"),
80
            ("pending", "Pending"),
81
            ("denied", "Denied"),
82
            ("removed", "Removed"),
83
        ]
84

85
    def queryset(self, request, queryset):
1✔
86
        # make list of app agreements for each status
87
        agreed_apps, denied_apps, removed_apps = [], [], []
1✔
88
        for app in App.objects.filter(agreement__isnull=False):
1✔
89
            if app.status().startswith("Agreed"):
×
90
                agreed_apps.append(app.id)
×
91
            elif app.status().startswith("Denied"):
×
92
                denied_apps.append(app.id)
×
93
            else:  # app.status().startswith('Removed'):
94
                removed_apps.append(app.id)
×
95

96
        if self.value() == "agreed":
1✔
97
            return queryset.filter(id__in=agreed_apps)
1✔
98

99
        if self.value() == "denied":
1✔
100
            return queryset.filter(id__in=denied_apps)
1✔
101

102
        if self.value() == "removed":
1✔
103
            return queryset.filter(id__in=removed_apps)
1✔
104

105
        if self.value() == "pending":
1✔
106
            return queryset.filter(agreement=None)
1✔
107

108

109
class AgreementInLine(admin.TabularInline):
1✔
110
    model = Agreement
1✔
111
    extra = 0
1✔
112
    can_delete = False
1✔
113
    list_display = [
1✔
114
        "__str__",
115
        "status",
116
        "agree_time",
117
        "expiration_date",
118
    ]
119
    fields = ["status", "agree_time", "expiration_date"]
1✔
120
    readonly_fields = ["agree_time", "expiration_date"]
1✔
121
    ordering = ["-agree_time"]
1✔
122

123
    def has_change_permission(self, request, obj=None):
1✔
124
        return False
×
125

126

127
@admin.register(Agreement, site=admin_site)
1✔
128
class AgreementAdmin(admin.ModelAdmin):
1✔
129
    model = Agreement
1✔
130
    date_hierarchy = "agree_time"
1✔
131
    list_display = [
1✔
132
        "__str__",
133
        "status",
134
        "agree_time",
135
        "expiration_date",
136
    ]
137
    list_filter = ["app"]
1✔
138

139

140
class NoteInLine(admin.TabularInline):
1✔
141
    model = Note
1✔
142
    extra = 0
1✔
143
    list_display = [
1✔
144
        "title",
145
        "created_on",
146
    ]
147
    fields = ["title", "body", "created_on"]
1✔
148
    readonly_fields = ["created_on"]
1✔
149
    ordering = ["-created_on"]
1✔
150

151
    def has_change_permission(self, request, obj=None):
1✔
152
        return False
×
153

154

155
class NoteAdmin(admin.ModelAdmin):
1✔
156
    model = Note
1✔
157

158

159
class AppInLine(admin.TabularInline):
1✔
160
    model = App
1✔
161
    extra = 0
1✔
162

163

164
@admin.register(App, site=admin_site)
1✔
165
class AppAdmin(admin.ModelAdmin):
1✔
166
    inlines = [AgreementInLine, NoteInLine]
1✔
167
    model = App
1✔
168

169
    list_filter = ("platform", AgreementFilter)
1✔
170
    list_display = (
1✔
171
        "__str__",
172
        "app_manager",
173
        "manager_contact",
174
        "app_sponsor",
175
        "sponsor_contact",
176
        "status",
177
        "platforms",
178
    )
179
    fields = [
1✔
180
        "name",
181
        "primary_language",
182
        "platform",
183
        "app_manager",
184
        "manager_contact",
185
        "app_sponsor",
186
        "sponsor_contact",
187
        "requestor",
188
        "status",
189
    ]
190
    readonly_fields = ["manager_contact", "sponsor_contact", "status"]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc