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


Python Article.author方法代码示例

本文整理汇总了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)
开发者ID:naughtond,项目名称:innuvate,代码行数:36,代码来源:views.py

示例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})
开发者ID:valencra,项目名称:django-blog,代码行数:16,代码来源:views.py

示例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))
开发者ID:cyrilsx,项目名称:smart_cms,代码行数:25,代码来源:views.py


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