| @@ 530-540 (lines=11) @@ | ||
| 527 | def __init__(self, context, request): |
|
| 528 | super(ajaxAttachmentsView, self).__init__(context, request) |
|
| 529 | ||
| 530 | @returns_json |
|
| 531 | def __call__(self): |
|
| 532 | protect.CheckAuthenticator(self.request.form) |
|
| 533 | ||
| 534 | if len(self.traverse_subpath) != 1: |
|
| 535 | return self.error("Not found", status=404) |
|
| 536 | func_name = "ajax_{}".format(self.traverse_subpath[0]) |
|
| 537 | func = getattr(self, func_name, None) |
|
| 538 | if func is None: |
|
| 539 | return self.error("Invalid function", status=400) |
|
| 540 | return func() |
|
| 541 | ||
| 542 | def error(self, message, status=500, **kw): |
|
| 543 | self.request.response.setStatus(status) |
|
| @@ 694-707 (lines=14) @@ | ||
| 691 | self.traverse_subpath.append(name) |
|
| 692 | return self |
|
| 693 | ||
| 694 | @returns_json |
|
| 695 | def __call__(self): |
|
| 696 | """Dispatch the path to a method and return JSON. |
|
| 697 | """ |
|
| 698 | protect.CheckAuthenticator(self.request.form) |
|
| 699 | protect.PostOnly(self.request.form) |
|
| 700 | ||
| 701 | if len(self.traverse_subpath) != 1: |
|
| 702 | return self.error("Not found", status=404) |
|
| 703 | func_name = "ajax_{}".format(self.traverse_subpath[0]) |
|
| 704 | func = getattr(self, func_name, None) |
|
| 705 | if func is None: |
|
| 706 | return self.error("Invalid function", status=400) |
|
| 707 | return func() |
|
| 708 | ||
| 709 | def error(self, message, status=500, **kw): |
|
| 710 | """Set a JSON error object and a status to the response |
|