| @@ 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) |
|
| @@ 720-733 (lines=14) @@ | ||
| 717 | self.traverse_subpath.append(name) |
|
| 718 | return self |
|
| 719 | ||
| 720 | @returns_json |
|
| 721 | def __call__(self): |
|
| 722 | """Dispatch the path to a method and return JSON. |
|
| 723 | """ |
|
| 724 | protect.CheckAuthenticator(self.request.form) |
|
| 725 | protect.PostOnly(self.request.form) |
|
| 726 | ||
| 727 | if len(self.traverse_subpath) != 1: |
|
| 728 | return self.error("Not found", status=404) |
|
| 729 | func_name = "ajax_{}".format(self.traverse_subpath[0]) |
|
| 730 | func = getattr(self, func_name, None) |
|
| 731 | if func is None: |
|
| 732 | return self.error("Invalid function", status=400) |
|
| 733 | return func() |
|
| 734 | ||
| 735 | def error(self, message, status=500, **kw): |
|
| 736 | """Set a JSON error object and a status to the response |
|