sites.py 文件源码

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

项目:baya 作者: counsyl 项目源码 文件源码
def get_urls(self):
        """Ensure that urls included in get_urls() are behind requires().

        We need to fix the include() logic for admin URLs. Django admin isn't
        very extensible, so we have to call super, remove the url patterns
        for model_admins that have a _gate, and replace the pattern with
        a properly built include behind the model admin's gate.

        Would be a lot easier if django exposed something like
        get_patterns_for_app(app_label), but noooooo.
        """
        # We have to maintain the URL ordering due to the way URLs are resolved
        # TODO - Test this, can lead to heisenbugs
        urls = OrderedDict((urlp.regex.pattern, urlp) for urlp in
                           super(NestedGroupsAdminSite, self).get_urls())
        for model, model_admin in self._get_admins_with_gate():
            if hasattr(model._meta, 'module_name'):
                model_name = model._meta.module_name
            elif hasattr(model._meta, 'model_name'):
                model_name = model._meta.model_name
            else:
                raise ValueError(
                    "Model Admin is missing a module or model name.")
            pattern = (
                r'^%s/%s/' %
                (model._meta.app_label, model_name))
            urls[pattern] = url(
                pattern,
                requires(get=model_admin._gate.get_requires,
                         post=model_admin._gate.post_requires)(
                             include(model_admin.urls)))
        return list(urls.values())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号