本文整理汇总了Python中models.Article.author方法的典型用法代码示例。如果您正苦于以下问题:Python Article.author方法的具体用法?Python Article.author怎么用?Python Article.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.author方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submitarticle
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import author [as 别名]
def submitarticle(request):
error_msg = u"No POST data sent."
if request.method == "POST":
post = request.POST.copy()
if post.has_key('tags') and post.has_key('title') and post.has_key('url'):
try:
url = post['url']
art = Article()
art.tags = post['tags'].strip().split(',')
art.author = str(request.user)
art.title = post['title']
art.votecount = 0
art.viewcount = 0
if not url.startswith('http://'):
url = 'http://'+url
art.url = url
if art.url and art.title and art.author:
try:
person = getPerson(request)
person.timesArticle = person.timesArticle + 1
person.lastActive = datetime.datetime.now()
rating = Score.objects(type='submitarticle')[0].value
person.currentRating = person.currentRating + rating
person.save()
incrementStat('articles',1)
art.save()
except Exception as inst:
print inst
return HttpResponseRedirect('/')
except:
return HttpResponseServerError('wowza! an error occurred, sorry!')
else:
error_msg = u"Insufficient POST data (need 'content' and 'title'!)"
return HttpResponseServerError(error_msg)
示例2: create
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import author [as 别名]
def create(request):
""" Create a new blog article
"""
# instantiate a new instance and populate fields from form data
article = Article()
article.title = request.POST.get("title", None)
article.author = request.user
article.content = request.POST.get("content", None)
# save new article, get updated articles list and user
article.save()
articles = Article.objects.all()
user = request.user
# render index page with updated data
return render(request, "index.html", {"testvar": "Test String 2!", "articles": articles, "user":user})
示例3: edit_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import author [as 别名]
def edit_article(request, id=None):
data = {}
article = Article()
if request.method == "POST":
form = ArticleForm(request.POST,instance=article) # A form bound to the POST data
if form.is_valid():
article.title = form.cleaned_data['title']
article.content = form.cleaned_data['content']
article.author = User.objects.get(pk=request.user.id)
article.save()
return HttpResponseRedirect('/blog/view/%s' % article.id)
elif request.method == "GET":
if id != None:
article = Article.objects.get(pk=id)
form = ArticleForm(instance=article)
else:
raise Http404
data['form'] = form
print form.errors
return render_to_response(BLOG_TEMPLATE + 'edit.html', data, context_instance=RequestContext(request))