utils.py 文件源码

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

项目:montage 作者: storyful 项目源码 文件源码
def make_overview(module, urls, namespace):
    """Given the URLs for a bunch of views and the module they came from this
    generates an overview page with a title, description and a list of links
    to execute the views.
    """
    title = get_module_name(module).title()
    description = module.__doc__

    class OverView(TemplateView):
        template_name = 'auto_task_overview.html'

        def get_context_data(self, **kwargs):
            ctx = super(OverView, self).get_context_data(**kwargs)
            ctx.update({'title': title, 'description': description})

            view_links = []
            for url in urls:
                view = url.callback
                view_links.append({
                    'url_name': '%s:%s' % (
                        namespace, url.name
                    ) if namespace else url.name,
                    'view_name': funcname(view, rep=' '),
                    'view_description': view.__doc__ or '',
                })

            ctx['view_links'] = sorted(
                view_links, key=lambda d: d['view_name'])
            return ctx

    return OverView.as_view()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号