utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:osp-api 作者: opensyllabus 项目源码 文件源码
def add_year_restriction(self, function):
        """Resource method decorator which applies a restriction
        only allowing results related to a syllabus of one year of
        age or older.

        This only works for HTTP GET methods on collection resources.
        Other methods will be unaffected entirely by this decorator.

        """

        method = function.__name__
        __, resource_type = self.resource_method_info(function)
        if method == "get" and resource_type == ResourceType.collection:
            @wraps(function)
            def new_function_to_replace_old(*args, **kwargs):
                request_args = {
                    'useOldIndex': True
                }
                request_args.update(flask.request.args)
                flask.request.args = ImmutableMultiDict(request_args)
                return function(*args, **kwargs)
            return new_function_to_replace_old
        else:
            return function


# TODO, FIXME: bad, remove this ASAP
# (this is here as filler because we haven't gotten
# to the elasticsearch bit yet)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号