本文整理汇总了Python中models.Article.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Article.parent方法的具体用法?Python Article.parent怎么用?Python Article.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.parent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import parent [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)