-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathadmin.py
More file actions
130 lines (101 loc) · 3.13 KB
/
admin.py
File metadata and controls
130 lines (101 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from django.contrib import admin
from django.contrib.auth.models import User
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _
from openwisp_utils.admin import (
AlwaysHasChangedMixin,
HelpTextStackedInline,
ReadOnlyAdmin,
ReceiveUrlAdmin,
Select2AdminMixin,
TimeReadonlyAdminMixin,
UUIDAdmin,
)
from openwisp_utils.admin_theme.filters import (
AutocompleteFilter,
InputFilter,
SimpleInputFilter,
)
from .models import (
Book,
Operator,
OrganizationRadiusSettings,
Project,
RadiusAccounting,
Shelf,
)
admin.site.unregister(User)
class AutoShelfFilter(AutocompleteFilter):
title = _("shelf")
field_name = "shelf"
parameter_name = "shelf__id"
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
list_display = ["username", "is_staff", "is_superuser", "is_active"]
list_filter = [
("username", InputFilter),
("shelf", InputFilter),
"is_staff",
"is_superuser",
"is_active",
]
search_fields = ("username",)
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_filter = [AutoShelfFilter, "name"]
search_fields = ["name"]
@admin.register(Operator)
class OperatorAdmin(admin.ModelAdmin):
list_display = ["first_name", "last_name"]
list_filter = ["project__name"] # DO NOT CHANGE: used for testing filters
@admin.register(RadiusAccounting)
class RadiusAccountingAdmin(ReadOnlyAdmin):
list_display = ["session_id", "username"]
fields = ["session_id", "username"]
class OperatorForm(AlwaysHasChangedMixin, ModelForm):
pass
class OperatorInline(HelpTextStackedInline):
model = Operator
form = OperatorForm
extra = 0
help_text = {
"text": _("Only added operators will have permission to access the project."),
"documentation_url": "https://github.com/openwisp/openwisp-utils/",
}
@admin.register(Project)
class ProjectAdmin(UUIDAdmin, ReceiveUrlAdmin):
inlines = [OperatorInline]
list_display = ("name",)
fields = ("uuid", "name", "key", "receive_url")
readonly_fields = ("uuid", "receive_url")
receive_url_name = "receive_project"
class ShelfFilter(SimpleInputFilter):
parameter_name = "shelf"
title = _("Shelf")
def queryset(self, request, queryset):
if self.value() is not None:
return queryset.filter(name__icontains=self.value())
class ReverseBookFilter(AutocompleteFilter):
title = _("Book")
field_name = "book"
parameter_name = "book"
class AutoOwnerFilter(AutocompleteFilter):
title = _("owner")
field_name = "owner"
parameter_name = "owner_id"
@admin.register(Shelf)
class ShelfAdmin(Select2AdminMixin, TimeReadonlyAdminMixin, admin.ModelAdmin):
# DO NOT CHANGE: used for testing filters
list_filter = [
ShelfFilter,
["books_type", InputFilter],
["id", InputFilter],
AutoOwnerFilter,
"books_type",
ReverseBookFilter,
]
search_fields = ["name"]
select2_fields = ("books_type",)
@admin.register(OrganizationRadiusSettings)
class OrganizationRadiusSettingsAdmin(admin.ModelAdmin):
pass