mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37:03 +02:00
refactored response_change to use a dictionary of action functions
This commit is contained in:
parent
889289f54e
commit
a398a5c927
1 changed files with 12 additions and 10 deletions
|
@ -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):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue