当前位置: 首页>>代码示例>>Python>>正文


Python Article.get_url_reverse方法代码示例

本文整理汇总了Python中models.Article.get_url_reverse方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get_url_reverse方法的具体用法?Python Article.get_url_reverse怎么用?Python Article.get_url_reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Article的用法示例。


在下文中一共展示了Article.get_url_reverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fetch_from_url

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_url_reverse [as 别名]
def fetch_from_url(request, url):
    """Analyze URL, returning the article and the articles in its path
    If something goes wrong, return an error HTTP response"""

    err = None
    article = None
    path = None
    
    url_path = get_url_path(url)

    try:
        root = Article.get_root()
        path = Article.get_url_reverse(url_path, root)
        if not path:
            print url_path
            err = not_found(request, '/' + '/'.join(url_path))
        else:
            article = path[-1]
    except:
        err = not_found(request, '')
    return (article, path, err)
开发者ID:JeffAMcGee,项目名称:infolab-site,代码行数:23,代码来源:views.py

示例2: create

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get_url_reverse [as 别名]
def create(request, wiki_url):
    
    url_path = get_url_path(wiki_url)

    if url_path != [] and url_path[0].startswith('_'):
            c = RequestContext(request, {'wiki_err_keyword': True,
                                         'wiki_url': '/'.join(url_path) })
            return render_to_response('simplewiki_error.html', c)        

    # Lookup path
    try:
        # Ensure that the path exists...
        root = Article.get_root()
        path = Article.get_url_reverse(url_path[:-1], root)
        if not path:
            c = RequestContext(request, {'wiki_err_noparent': True,
                                         'wiki_url_parent': '/'.join(url_path[:-1]) })
            return render_to_response('simplewiki_error.html', c)
        
        perm_err = check_permissions(request, path[-1], check_locked=False, check_write=True)
        if perm_err:
            return perm_err
        # Ensure doesn't already exist
        article = Article.get_url_reverse(url_path, root)
        if article:
            return HttpResponseRedirect(reverse('wiki_view', args=(article[-1].get_url(),)))
    
        # TODO: Somehow this doesnt work... 
        #except ShouldHaveExactlyOneRootSlug, (e):
    except:
        if Article.objects.filter(parent=None).count() > 0:
            return HttpResponseRedirect(reverse('wiki_view', args=('',)))
        # Root not found...
        path = []
        url_path = [""]

    if request.method == 'POST':
        f = CreateArticleForm(request.POST)
        if f.is_valid():
            article = Article()
            article.slug = url_path[-1]
            if not request.user.is_anonymous():
                article.created_by = request.user
            article.title = f.cleaned_data.get('title')
            if path != []:
                article.parent = path[-1]
            a = article.save()
            new_revision = f.save(commit=False)
            if not request.user.is_anonymous():
                new_revision.revision_user = request.user
            new_revision.article = article
            new_revision.save()
            import django.db as db
            return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
    else:
        f = CreateArticleForm(initial={'title':request.GET.get('wiki_article_name', url_path[-1]),
                                       'contents':_('Headline\n===\n\n')})
        
    c = RequestContext(request, {'wiki_form': f,
                                 'wiki_write': True,
                                 })

    return render_to_response('simplewiki_create.html', c)
开发者ID:JeffAMcGee,项目名称:infolab-site,代码行数:65,代码来源:views.py


注:本文中的models.Article.get_url_reverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。