Mercurial > p > roundup > code
comparison roundup/rest.py @ 5926:3ca3bfe6de16
Code-robustness, error-message improved
.. for REST-API PATCH method with @op = action
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Tue, 15 Oct 2019 16:23:06 +0200 |
| parents | 2b78e21d7047 |
| children | 5d0873a4de4a |
comparison
equal
deleted
inserted
replaced
| 5925:7cf8f6389aad | 5926:3ca3bfe6de16 |
|---|---|
| 1413 | 1413 |
| 1414 # if patch operation is action, call the action handler | 1414 # if patch operation is action, call the action handler |
| 1415 action_args = [class_name + item_id] | 1415 action_args = [class_name + item_id] |
| 1416 if op == 'action': | 1416 if op == 'action': |
| 1417 # extract action_name and action_args from form fields | 1417 # extract action_name and action_args from form fields |
| 1418 name = None | |
| 1418 for form_field in input.value: | 1419 for form_field in input.value: |
| 1419 key = form_field.name | 1420 key = form_field.name |
| 1420 value = form_field.value | 1421 value = form_field.value |
| 1421 if key == "@action_name": | 1422 if key == "@action_name": |
| 1422 name = value | 1423 name = value |
| 1425 | 1426 |
| 1426 if name in self.actions: | 1427 if name in self.actions: |
| 1427 action_type = self.actions[name] | 1428 action_type = self.actions[name] |
| 1428 else: | 1429 else: |
| 1429 raise UsageError( | 1430 raise UsageError( |
| 1430 'action "%s" is not supported %s' % | 1431 'action "%s" is not supported, allowed: %s' % |
| 1431 (name, ','.join(self.actions.keys())) | 1432 (name, ', '.join(self.actions.keys())) |
| 1432 ) | 1433 ) |
| 1433 action = action_type(self.db, self.translator) | 1434 action = action_type(self.db, self.translator) |
| 1434 result = action.execute(*action_args) | 1435 result = action.execute(*action_args) |
| 1435 | 1436 |
| 1436 result = { | 1437 result = { |
