1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add custom get_operation_id() method to avoid monkey-patching coreapi

This commit is contained in:
Jeremy Stretch
2020-11-11 14:25:43 -05:00
parent 963df7e398
commit 64d1f57276
2 changed files with 12 additions and 15 deletions

View File

@@ -12,6 +12,18 @@ from netbox.api import ChoiceField, SerializedPKRelatedField, WritableNestedSeri
class NetBoxSwaggerAutoSchema(SwaggerAutoSchema):
writable_serializers = {}
def get_operation_id(self, operation_keys=None):
operation_keys = operation_keys or self.operation_keys
operation_id = self.overrides.get('operation_id', '')
if not operation_id:
# Overwrite the action for bulk update/bulk delete views to ensure they get an operation ID that's
# unique from their single-object counterparts (see #3436)
if operation_keys[-1] in ('delete', 'partial_update', 'update') and not self.view.detail:
operation_keys[-1] = f'bulk_{operation_keys[-1]}'
operation_id = '_'.join(operation_keys)
return operation_id
def get_request_serializer(self):
serializer = super().get_request_serializer()