Skip to content

Commit

Permalink
Merge pull request #215 from jsocol/disable-action
Browse files Browse the repository at this point in the history
Remove global delete action
  • Loading branch information
jsocol committed May 30, 2016
2 parents 99d6663 + 90d237c commit 3433195
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions waffle/admin.py
Expand Up @@ -5,6 +5,14 @@
from waffle.models import Flag, Sample, Switch


class BaseAdmin(admin.ModelAdmin):
def get_actions(self, request):
actions = super(BaseAdmin, self).get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
return actions


def enable_for_all(ma, request, qs):
# Iterate over all objects to cause cache invalidation.
for f in qs.all():
Expand All @@ -21,16 +29,15 @@ def disable_for_all(ma, request, qs):
disable_for_all.short_description = 'Disable selected flags for everyone.'


def delete_flags(ma, request, qs):
def delete_individually(ma, request, qs):
# Iterate over all objects to cause cache invalidation.
for f in qs.all():
f.delete()
delete_flags.short_description = 'Delete the selected flags.'
delete_individually.short_description = 'Delete selected.'


class FlagAdmin(admin.ModelAdmin):
actions = [enable_for_all, disable_for_all, delete_flags]
date_hierarchy = 'created'
class FlagAdmin(BaseAdmin):
actions = [enable_for_all, disable_for_all, delete_individually]
list_display = ('name', 'note', 'everyone', 'percent', 'superusers',
'staff', 'authenticated', 'languages')
list_filter = ('everyone', 'superusers', 'staff', 'authenticated')
Expand All @@ -52,16 +59,15 @@ def disable_switches(ma, request, qs):
disable_switches.short_description = 'Disable the selected switches.'


class SwitchAdmin(admin.ModelAdmin):
actions = [enable_switches, disable_switches]
date_hierarchy = 'created'
class SwitchAdmin(BaseAdmin):
actions = [enable_switches, disable_switches, delete_individually]
list_display = ('name', 'active', 'note', 'created', 'modified')
list_filter = ('active',)
ordering = ('-id',)


class SampleAdmin(admin.ModelAdmin):
date_hierarchy = 'created'
class SampleAdmin(BaseAdmin):
actions = [delete_individually]
list_display = ('name', 'percent', 'note', 'created', 'modified')
ordering = ('-id',)

Expand Down

0 comments on commit 3433195

Please sign in to comment.