Пример #1
0
    def delete(self):
        authenticated, this_user = utils.process_cookie(self.request)
        if not authenticated:
            self.response.status = 401
            return

        url_obj = urlparse.urlparse(str(self.request.url))
        subdirs = str(url_obj.path).split('/')
        num_layers = len(subdirs)
        last_dir_string = str(subdirs[len(subdirs)-1])

        if num_layers == 3:
            try:
                target_dish = int(last_dir_string)
                dishHandler.delete_dish(self, this_user, target_dish)
            except ValueError:
                self.response.status = 405
        elif num_layers == 4:
            try:
                target_dish = int(subdirs[2])
                subdir_string = str(last_dir_string)
                handling_function = delete_sub_routes["DELETE_" + subdir_string]
                getattr(globals()[subdir_string + "Handler"], handling_function)(self, this_user, target_dish)
            except ValueError:
                self.response.status = 405
            except KeyError:
                self.response.status = 405
        elif num_layers == 5 and subdirs[3] == 'comment':
            try:
                target_dish = int(subdirs[2])
                target_comment = int(last_dir_string)
                commentHandler.delete_comment(self, this_user, target_dish, target_comment)
            except ValueError:
                self.response.status = 405
        else:
            self.response.status = 405