| @@ 543-553 (lines=11) @@ | ||
| 540 | def __init__(self, context, request): |
|
| 541 | super(ajaxAttachmentsView, self).__init__(context, request) |
|
| 542 | ||
| 543 | @returns_json |
|
| 544 | def __call__(self): |
|
| 545 | protect.CheckAuthenticator(self.request.form) |
|
| 546 | ||
| 547 | if len(self.traverse_subpath) != 1: |
|
| 548 | return self.error("Not found", status=404) |
|
| 549 | func_name = "ajax_{}".format(self.traverse_subpath[0]) |
|
| 550 | func = getattr(self, func_name, None) |
|
| 551 | if func is None: |
|
| 552 | return self.error("Invalid function", status=400) |
|
| 553 | return func() |
|
| 554 | ||
| 555 | def error(self, message, status=500, **kw): |
|
| 556 | self.request.response.setStatus(status) |
|
| @@ 721-734 (lines=14) @@ | ||
| 718 | self.traverse_subpath.append(name) |
|
| 719 | return self |
|
| 720 | ||
| 721 | @returns_json |
|
| 722 | def __call__(self): |
|
| 723 | """Dispatch the path to a method and return JSON. |
|
| 724 | """ |
|
| 725 | protect.CheckAuthenticator(self.request.form) |
|
| 726 | protect.PostOnly(self.request.form) |
|
| 727 | ||
| 728 | if len(self.traverse_subpath) != 1: |
|
| 729 | return self.error("Not found", status=404) |
|
| 730 | func_name = "ajax_{}".format(self.traverse_subpath[0]) |
|
| 731 | func = getattr(self, func_name, None) |
|
| 732 | if func is None: |
|
| 733 | return self.error("Invalid function", status=400) |
|
| 734 | return func() |
|
| 735 | ||
| 736 | def error(self, message, status=500, **kw): |
|
| 737 | """Set a JSON error object and a status to the response |
|