Пример #1
0
    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
Пример #2
0
    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)
Пример #3
0
    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()
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
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]
    }