mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-22 00:38:41 +02:00
Move ModelAction validation into __post_init__
This commit is contained in:
@@ -32,6 +32,12 @@ class ModelAction:
|
|||||||
name: str
|
name: str
|
||||||
help_text: str = ''
|
help_text: str = ''
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
if not self.name:
|
||||||
|
raise ValueError("Action name must not be empty.")
|
||||||
|
if self.name in RESERVED_ACTIONS:
|
||||||
|
raise ValueError(f"'{self.name}' is a reserved action and cannot be registered.")
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.name)
|
return hash(self.name)
|
||||||
|
|
||||||
@@ -54,10 +60,6 @@ def register_model_actions(model: type[Model], actions: list[ModelAction | str])
|
|||||||
for action in actions:
|
for action in actions:
|
||||||
if isinstance(action, str):
|
if isinstance(action, str):
|
||||||
action = ModelAction(name=action)
|
action = ModelAction(name=action)
|
||||||
if not action.name:
|
|
||||||
raise ValueError("Action name must not be empty.")
|
|
||||||
if action.name in RESERVED_ACTIONS:
|
|
||||||
raise ValueError(f"'{action.name}' is a reserved action and cannot be registered.")
|
|
||||||
registry['model_actions'][label].add(action)
|
registry['model_actions'][label].add(action)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user