def get_object(self, queryset=None): key = self.kwargs.get('key') if not key: raise Http404 article = ArticleModel.get(Key(key)) if not article: raise Http404 return article
def form_valid(self, form): title = form.cleaned_data['title'] body = form.cleaned_data['body'] article = ArticleModel.create(title, body, self.request.user) self.key = article.put() return super(AddArticleView, self).form_valid(form)
def get_initial(self): key = self.kwargs.get('key') if not key: raise Http404 self.key = Key(key) article = ArticleModel.get(self.key) if not article: raise Http404 return article.to_safe_dict()
def get_context_data(self, **kwargs): key = kwargs.get('key') if not key: raise Http404 article_key = Key(key) article = ArticleModel.get(article_key) if not article: raise Http404 kwargs['article'] = article.to_safe_dict() return super(ArticleView, self).get_context_data(**kwargs)
def form_valid(self, form): title = form.cleaned_data['title'] body = form.cleaned_data['body'] key = form.cleaned_data['key'] article = ArticleModel.get(Key(key)) article.update(title, body, self.request.user) article.put() return super(UpdateArticleView, self).form_valid(form)
def recent_articles(request): memcache_key = 'recent_articles' ras = memcache.get(memcache_key) if ras is None: max_articles = 5 cache_timeout = 5 ras = ArticleModel.gql('ORDER BY created DESC').fetch(max_articles) memcache.add(memcache_key, ras, cache_timeout) return { 'recent_articles' : [ra.to_safe_dict() for ra in ras] }