views.py 文件源码

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

项目:django-chartwerk 作者: DallasMorningNews 项目源码 文件源码
def get_context_data(self, **kwargs):
        context = super(ChartIconMixin, self).get_context_data(**kwargs)

        # Get all the template icons and them in a dict we can use as a
        # lookup
        icons = Template.objects.defer('data')
        icon_lookup = {i.title: i.icon for i in icons}

        default_icon = static('chartwerk/img/chartwerk_100.png')

        for chart in context[self.context_object_name]:
            tpl_title = chart.data['template']['title']

            # If the chart template isn't found or it's icon field is null,
            # use default
            if not icon_lookup.get(tpl_title):
                chart.icon = default_icon
            else:
                chart.icon = icon_lookup[tpl_title].url

        return context
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号