Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qcat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ISRIC
wocat
qcat
Commits
5a91d884
Commit
5a91d884
authored
1 year ago
by
Andreas Nüßlein
Committed by
Andreas Nüßlein (sinnwerkstatt)
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
django admin token handling improvement
(cherry picked from commit
17b09e4f
)
parent
738b7a57
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/accounts/admin.py
+29
-6
29 additions, 6 deletions
apps/accounts/admin.py
apps/api/admin.py
+2
-1
2 additions, 1 deletion
apps/api/admin.py
with
31 additions
and
7 deletions
apps/accounts/admin.py
+
29
−
6
View file @
5a91d884
from
django
import
forms
from
django
import
forms
from
django.contrib
import
admin
from
django.contrib
import
admin
from
django.contrib.admin
import
SimpleListFilter
from
django.contrib.auth
import
admin
as
auth_admin
from
django.contrib.auth
import
admin
as
auth_admin
from
django.contrib.auth.models
import
Group
from
django.contrib.auth.models
import
Group
from
apps.accounts.models
import
User
from
apps.accounts.models
import
User
from
apps.api.models
import
NoteToken
class
CustomUserChangeForm
(
forms
.
ModelForm
):
class
CustomUserChangeForm
(
forms
.
ModelForm
):
...
@@ -19,12 +21,30 @@ class CustomUserChangeForm(forms.ModelForm):
...
@@ -19,12 +21,30 @@ class CustomUserChangeForm(forms.ModelForm):
pass
pass
class
UserAdmin
(
auth_admin
.
UserAdmin
):
class
TokenAdmin
(
admin
.
StackedInline
):
"""
max_num
=
1
The representation of :class:`accounts.models.User` in the
min_num
=
0
administration interface.
model
=
NoteToken
"""
can_delete
=
False
show_change_link
=
True
readonly_fields
=
[
"
key
"
]
class
TokenFilter
(
SimpleListFilter
):
title
=
"
has_token
"
parameter_name
=
"
has_token
"
def
lookups
(
self
,
request
,
model_admin
):
return
[(
"
✓
"
,
"
True
"
),
(
"
x
"
,
"
False
"
)]
def
queryset
(
self
,
request
,
queryset
):
if
self
.
value
()
==
"
✓
"
:
return
queryset
.
filter
(
auth_token__isnull
=
False
)
if
self
.
value
():
return
queryset
.
filter
(
auth_token__isnull
=
True
)
class
UserAdmin
(
auth_admin
.
UserAdmin
):
form
=
CustomUserChangeForm
form
=
CustomUserChangeForm
list_display
=
(
list_display
=
(
...
@@ -35,8 +55,9 @@ class UserAdmin(auth_admin.UserAdmin):
...
@@ -35,8 +55,9 @@ class UserAdmin(auth_admin.UserAdmin):
"
is_superuser
"
,
"
is_superuser
"
,
"
date_joined
"
,
"
date_joined
"
,
"
last_login
"
,
"
last_login
"
,
"
auth_token
"
,
)
)
list_filter
=
(
"
is_superuser
"
,
"
groups
"
)
list_filter
=
(
"
is_superuser
"
,
"
groups
"
,
TokenFilter
)
search_fields
=
(
"
email
"
,)
search_fields
=
(
"
email
"
,)
ordering
=
(
"
email
"
,)
ordering
=
(
"
email
"
,)
filter_horizontal
=
(
"
groups
"
,)
filter_horizontal
=
(
"
groups
"
,)
...
@@ -47,6 +68,8 @@ class UserAdmin(auth_admin.UserAdmin):
...
@@ -47,6 +68,8 @@ class UserAdmin(auth_admin.UserAdmin):
)
)
readonly_fields
=
(
"
email
"
,)
readonly_fields
=
(
"
email
"
,)
inlines
=
[
TokenAdmin
]
# No new users can be added.
# No new users can be added.
def
has_add_permission
(
self
,
request
):
def
has_add_permission
(
self
,
request
):
return
False
return
False
...
...
This diff is collapsed.
Click to expand it.
apps/api/admin.py
+
2
−
1
View file @
5a91d884
...
@@ -12,5 +12,6 @@ class RequestLogAdmin(admin.ModelAdmin):
...
@@ -12,5 +12,6 @@ class RequestLogAdmin(admin.ModelAdmin):
@admin.register
(
NoteToken
)
@admin.register
(
NoteToken
)
class
NoteTokenAdmin
(
admin
.
ModelAdmin
):
class
NoteTokenAdmin
(
admin
.
ModelAdmin
):
fields
=
[
"
user
"
,
"
notes
"
]
fields
=
[
"
user
"
,
"
notes
"
,
"
key
"
]
readonly_fields
=
[
"
key
"
]
list_display
=
[
"
__str__
"
,
"
user
"
,
"
created
"
,
"
requests_from_user
"
]
list_display
=
[
"
__str__
"
,
"
user
"
,
"
created
"
,
"
requests_from_user
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment