Exemplo n.º 1
0
    def get(self):
        """
        Generate an RSS feed with the lastest blog posts
        TODO: Caching
        """

        # Check if cached
        cache_key = 'written_rss_main'
        rss_content = ubercache.cache_get(cache_key)
        if rss_content:
            self.response.headers['Content-Type'] = 'application/xml'
            self.response.write(rss_content)
            return

        # Not cached, so render and store it

        ctx = {'posts': []}

        entities, cursor, more = posts_api.get_posts(limit=25, is_published=True)
        posts_api.bulk_dereference_posts(entities)

        # Create A set of results based upon this result set - iterator??
        ctx['posts'] = entities

        rss_content = self.render_template('./templates/newsfeeds/rss.html', ctx, to_string=True)

        # Set Cache
        ubercache.cache_set(cache_key, rss_content, category='written')

        self.response.headers['Content-Type'] = 'application/xml'
        self.response.write(rss_content)
        return
Exemplo n.º 2
0
    def get_dereferenced_post(self, slug):
        """
        Helper method to get a
        """
        post = posts_api.get_post_by_slug(slug)
        if not post:
            return None

        posts_api.bulk_dereference_posts([post])
        return post
Exemplo n.º 3
0
    def get(self, category_slug, slug):
        post = self.get_dereferenced_post(slug)
        if not post:
            return self.serve_404('Post Not Found')

        posts_api.bulk_dereference_posts([post])

        # Step 2: Redirection Logic if category slug doesn't match

        # Step 3: Serve Up Article
        self.serve_up_article(post)
Exemplo n.º 4
0
    def get(self):
        """
        Written Main Page Web Handler
        """

        pagemeta = {
            'title': 'Written',
            'description': 'Writing and Critique',
            'image': DEFAULT_POST_IMAGE
        }

        # TEMP: Get List of posts for serverside rendering
        entities, cursor, more = posts_api.get_posts(limit=25, cursor=None)
        posts_api.bulk_dereference_posts(entities)

        # Create A set of results based upon this result set - iterator??
        results = []
        for e in entities:
            results.append(Resource(e, REST_RULES).to_dict())


        template_values = {'pagemeta': pagemeta, 'entities': results}
        self.render_template('./templates/v0/bloglist.html', template_values)
Exemplo n.º 5
0
    def _get(self):
        """
        Get a collection of Written Posts
        """

        # Check if we want to get a post by its slug
        get_by_slug = self.cleaned_params.get('get_by_slug', None)

        if get_by_slug:
            return self._get_by_slug_or_404(get_by_slug)

        # Get a list of all posts

        limit = self.cleaned_params.get('limit', None)
        cursor = self.cleaned_params.get('cursor', None)
        start_date = self.cleaned_params.get('start_date', None)
        category_slug = self.cleaned_params.get('category_slug', None)

        optional_params = {}

        if 'is_published' in self.params:
            optional_params['is_published'] = self.cleaned_params['is_published']

        if start_date:
            optional_params['start_date'] = start_date

        category_resource_id_filter = None
        if category_slug:
            category = posts_api.get_post_category_by_slug(category_slug)

            if not category:
                self.serve_404('Category with slug %s Not Found' % category_slug)
                return

            optional_params['category_resource_id'] = get_resource_id_from_key(category.key)

        # TODO: If you are not admin, default is_published to True...

        key_stamp = str(hash(json.dumps(self.params)))
        cache_key = 'written_resources_%s' % key_stamp

        cached_result = ubercache.cache_get(cache_key)
        if False and cached_result:
            results, cursor, more = cached_result
        else:
            # Posts were not Cached for this set of properties

            entities, cursor, more = posts_api.get_posts(limit=limit, cursor=cursor, **optional_params)
            posts_api.bulk_dereference_posts(entities)

            # Create A set of results based upon this result set - iterator??
            results = []
            for e in entities:
                results.append(Resource(e, REST_RULES).to_dict())

            if cursor:
                cursor = cursor.urlsafe()

            # Store In Cache
            ubercache.cache_set(cache_key, (results, cursor, more), category='written')

        self.serve_success(results, {'cursor': cursor, 'more': more})