-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathadmin.py
47 lines (39 loc) · 1.42 KB
/
admin.py
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
from typing import List
from django.http import HttpRequest, HttpResponse
from django.urls import URLPattern, re_path
from bananas import admin
@admin.register()
class SimpleAdminView(admin.AdminView):
permissions = [
("can_do_special_stuff", "Can do special stuff"),
]
tools = [
("Special Action", "admin:tests_simple_special", "can_do_special_stuff"),
admin.ViewTool(
"Even more special action",
"https://example.org",
html_class="addlink",
),
]
def get_urls(self) -> List[URLPattern]:
return [
re_path(
r"^custom/$",
self.admin_view(self.custom_view),
name="tests_simple_custom",
),
re_path(
r"^special/$",
self.admin_view(
self.special_permission_view, perm="can_do_special_stuff"
),
name="tests_simple_special",
),
]
def get(self, request: HttpRequest) -> HttpResponse:
return self.render("simple.html", {"context": "get"})
def custom_view(self, request: HttpRequest) -> HttpResponse:
assert self.has_access() # For coverage...
return self.render("simple.html", {"context": "custom"})
def special_permission_view(self, request: HttpRequest) -> HttpResponse:
return self.render("simple.html", {"context": "special"})