Feat/confirm actions (#2)
* Working wrapper for actions * checking permissions for action * Refactor/clean change_confirmation template a bit * Update README * Update README * Adding unit tests for confirm_action decorator * Updated tests/readme * Update after testing upload to test pypi * Clean up and format code Co-authored-by: Thu Trang Pham <thu@joinmodernhealth.com>
This commit is contained in:
+16
-1
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
from admin_confirm.admin import AdminConfirmMixin, confirm_action
|
||||
|
||||
from .models import Item, Inventory, Shop
|
||||
|
||||
@@ -20,6 +20,21 @@ class InventoryAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
class ShopAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
confirmation_fields = ["name"]
|
||||
|
||||
actions = ["show_message", "show_message_no_confirmation"]
|
||||
|
||||
@confirm_action
|
||||
def show_message(modeladmin, request, queryset):
|
||||
shops = ", ".join(shop.name for shop in queryset)
|
||||
modeladmin.message_user(request, f"You selected with confirmation: {shops}")
|
||||
|
||||
show_message.allowed_permissions = ('delete',)
|
||||
|
||||
def show_message_no_confirmation(modeladmin, request, queryset):
|
||||
shops = ", ".join(shop.name for shop in queryset)
|
||||
modeladmin.message_user(request, f"You selected without confirmation: {shops}")
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return request.user.is_superuser
|
||||
|
||||
admin.site.register(Item, ItemAdmin)
|
||||
admin.site.register(Inventory, InventoryAdmin)
|
||||
|
||||
@@ -24,7 +24,7 @@ SECRET_KEY = "=yddl-40388w3e2hl$e8)revce=n67_idi8pfejtn3!+2%!_qt"
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["127.0.0.1"]
|
||||
ALLOWED_HOSTS = ["127.0.0.1", "localhost"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
Reference in New Issue
Block a user