Optimize the declaration of view actions #8511

Closed
opened 2025-12-29 20:37:36 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Aug 24, 2023).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

ActionsMixin defines two attributes on a view:

  • actions - A tuple of support action names
  • action_perms - A dictionary mapping of action names to a set of required permissions for each

The following actions are defined by default:

    actions = ('add', 'import', 'export', 'bulk_edit', 'bulk_delete')
    action_perms = defaultdict(set, **{
        'add': {'add'},
        'import': {'add'},
        'bulk_edit': {'change'},
        'bulk_delete': {'delete'},
    })

These can be combined into a single mapping:

    actions = {
        'add': {'add'},
        'import': {'add'},
        'export': set(),
        'bulk_edit': {'change'},
        'bulk_delete': {'delete'},
    }

Justification

This change will simplify the list of support actions for a view and reduce duplicate code.

Originally created by @jeremystretch on GitHub (Aug 24, 2023). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes `ActionsMixin` defines two attributes on a view: * `actions` - A tuple of support action names * `action_perms` - A dictionary mapping of action names to a set of required permissions for each The following actions are defined by default: ```python actions = ('add', 'import', 'export', 'bulk_edit', 'bulk_delete') action_perms = defaultdict(set, **{ 'add': {'add'}, 'import': {'add'}, 'bulk_edit': {'change'}, 'bulk_delete': {'delete'}, }) ``` These can be combined into a single mapping: ```python actions = { 'add': {'add'}, 'import': {'add'}, 'export': set(), 'bulk_edit': {'change'}, 'bulk_delete': {'delete'}, } ``` ### Justification This change will simplify the list of support actions for a view and reduce duplicate code.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:37:36 +01:00
adam closed this issue 2025-12-29 20:37:36 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8511