Python django.views.generic.base 模块,ContextMixin() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用django.views.generic.base.ContextMixin()

项目:talkativot    作者:lablup    | 项目源码 | 文件源码
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}