refactored response_change to use a dictionary of action functions

This commit is contained in:
David Kennedy 2023-09-12 11:04:26 -04:00
parent 889289f54e
commit a398a5c927
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -175,17 +175,19 @@ class DomainAdmin(ListHeaderAdmin):
readonly_fields = ["state"] readonly_fields = ["state"]
def response_change(self, request, obj): def response_change(self, request, obj):
ACTION_BUTTONS = { # Create dictionary of action functions
"PLACE_HOLD": "_place_client_hold", ACTION_FUNCTIONS = {
"REMOVE_HOLD": "_remove_client_hold", "_place_client_hold": self.do_place_client_hold,
"EDIT_DOMAIN": "_edit_domain", "_remove_client_hold": self.do_remove_client_hold,
"_edit_domain": self.do_edit_domain,
} }
if ACTION_BUTTONS["PLACE_HOLD"] in request.POST:
return self.do_place_client_hold(request, obj) # Check which action button was pressed and call the corresponding function
elif ACTION_BUTTONS["REMOVE_HOLD"] in request.POST: for action, function in ACTION_FUNCTIONS.items():
return self.do_remove_client_hold(request, obj) if action in request.POST:
elif ACTION_BUTTONS["EDIT_DOMAIN"] in request.POST: return function(request, obj)
return self.do_edit_domain(request, obj)
# If no matching action button is found, return the super method
return super().response_change(request, obj) return super().response_change(request, obj)
def do_place_client_hold(self, request, obj): def do_place_client_hold(self, request, obj):