本文整理汇总了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)
示例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)