-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/add flush expired tokens command to admin #721
base: master
Are you sure you want to change the base?
Feat/add flush expired tokens command to admin #721
Conversation
@Andrew-Chen-Wang Ready for review. |
@@ -67,6 +68,31 @@ class BlacklistedTokenAdmin(admin.ModelAdmin): | |||
"token__jti", | |||
) | |||
ordering = ("token__user",) | |||
actions = ["flush_expired_tokens"] | |||
|
|||
def flush_expired_tokens(self, request, queryset): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def flush_expired_tokens(self, request, queryset): | |
@admin.action(permissions=["change"], description = _("Flush expired tokens")) | |
def flush_expired_tokens(self, request, queryset): |
What are your thoughts on using the @admin.action decorator?
It allows you to set the required permissions for executing an action and provides a description for it as well. Additionally, you can use gettext_lazy to provide localization support. @tpotjj
Can you please execute the 'makemessages' command to generate the 'po' file? @tpotjj |
Doing this as a cronjob might be the better way of doing it, but for a smaller project that doesn't allow setting up a cronjob or because of the lack of knowledge, it might be convenient to add this to the Admin.