Code Duplication    Length = 11-14 lines in 2 locations

bika/lims/browser/analysisrequest/add2.py 1 location

@@ 707-720 (lines=14) @@
704
        self.traverse_subpath.append(name)
705
        return self
706
707
    @returns_json
708
    def __call__(self):
709
        """Dispatch the path to a method and return JSON.
710
        """
711
        protect.CheckAuthenticator(self.request.form)
712
        protect.PostOnly(self.request.form)
713
714
        if len(self.traverse_subpath) != 1:
715
            return self.error("Not found", status=404)
716
        func_name = "ajax_{}".format(self.traverse_subpath[0])
717
        func = getattr(self, func_name, None)
718
        if func is None:
719
            return self.error("Invalid function", status=400)
720
        return func()
721
722
    def error(self, message, status=500, **kw):
723
        """Set a JSON error object and a status to the response

bika/lims/browser/attachment.py 1 location

@@ 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)