本文整理汇总了Python中models.Article.get方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get方法的具体用法?Python Article.get怎么用?Python Article.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: article_delete
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get [as 别名]
def article_delete(request, key):
if not key:
return redirect(article_list)
if request.POST.get('confirmation') == 'yes':
m = Article.get(key)
if m:
m.delete()
Article.get(key) # for refreshing purposes http://stackoverflow.com/questions/15773892/should-i-expect-stale-results-after-redirect-on-local-environment
if request.POST.get('confirmation'):
return redirect(article_list)
return render_to_response("confirmation.html", {}, context_instance=RequestContext(request))
示例2: article_add
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get [as 别名]
def article_add(request):
if request.method == 'POST':
formset = ArticleForm(request.POST)
if formset.is_valid():
instance = formset.save()
Article.get(instance.key())
return redirect(article_list)
else:
formset = ArticleForm()
return render_to_response("articles_add.html", {
"formset": formset,
}, context_instance=RequestContext(request))
示例3: createArticle
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get [as 别名]
def createArticle(self, request):
"""Create new Article object, returning ArticleForm/request."""
for required in ['title', 'content']:
if not getattr(request, required):
raise endpoints.BadRequestException("Article '%s' field required" % required)
# copy ArticleForm/ProtoRPC Message into dict
data = {field.name: getattr(request, field.name) for field in request.all_fields()}
if data['view'] == None:
del data['view']
else:
data['view'] = str(data['view'])
author = self._getAuthorFromUser()
data['authorName'] = author.displayName
article_id = Article.allocate_ids(size=1, parent=author.key)[0]
article_key = ndb.Key(Article, article_id, parent=author.key)
data['key'] = article_key
# create Article
article_key = Article(**data).put()
# send email to author confirming creation of Article
taskqueue.add(params={'email': author.mainEmail,
'ArticleInfo': repr(request)},
url='/tasks/send_confirmation_email'
)
return self._copyArticleToForm(article_key.get(), author=author)
示例4: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import get [as 别名]
def post(self):
article = self.request.POST.get('id')
instance = Article.get(article) if article else None
data = ArticleForm(data=self.request.POST, instance=instance)
if data.is_valid():
entity = data.save(commit=False)
if hasattr(self.request.POST.get('img'), 'file'):
entity.img = Blob(self.request.POST.get('img').file.read())
entity.put()
self.redirect_to("new", message='Статья успешно сохранена!')
else:
self.response.out.write(render('templates/article.html', {'form': data}))