python类ContextMixin()的实例源码

mixins.py 文件源码 项目:talkativot 作者: lablup 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_json_data(self, context):
        '''
        Default implementation: remove some auto-injected but not
        JSON-serializable context variables.
        If self.context_json_filter is set to a collection such as list or
        set, then it instead preserves only the key-value pairs whose key is
        in the filter.

        You may override this method to implement your own serialization and
        context filtering process.
        '''
        if self.context_json_filter is None:
            if isinstance(self, SingleObjectMixin):
                name = self.get_context_object_name(self.object)
                if name in context: del context[name]
                if 'object' in context: del context['object']
            if isinstance(self, ContextMixin):
                if 'view' in context: del context['view']
            return context
        else:
            return {k: v for k, v in context.items()
                    if k in self.context_json_filter}


问题


面经


文章

微信
公众号

扫码关注公众号