Beispiel #1
0
    def render_atom(self, content_type, templates, **context):
        feed_name = (
            f"{app.theme_context.get('SITENAME')}"
            f" | {content_type.title()} | atom feed"
        )
        if context.get('articles_page'):
            contents = context['articles_page'].object_list
        else:
            contents = context['articles']

        feed = AtomFeed(
            feed_name,
            feed_url=request.url,
            url=request.url_root
        )
        for content in contents:
            content = make_model(content)
            feed.add(
                content.title,
                cdata(content.content),
                content_type="html",
                author=content.author,
                url=make_external_url(content.url),
                updated=content.modified,
                published=content.date
            )
        return feed.get_response()
Beispiel #2
0
    def render_atom(self, content_type, templates, **context):
        feed_name = (
            f"{app.theme_context.get('SITENAME')}"
            f" | {content_type.title()} | atom feed"
        )
        if context.get('articles_page'):
            contents = context['articles_page'].object_list
        else:
            contents = context['articles']

        feed = AtomFeed(
            feed_name,
            feed_url=request.url,
            url=request.url_root
        )
        for content in contents:
            content = make_model(content)
            feed.add(
                content.title,
                cdata(content.content),
                content_type="html",
                author=content.author,
                url=make_external_url(content.url),
                updated=content.modified,
                published=content.date
            )
        return feed.get_response()
Beispiel #3
0
    def render_rss(self, content_type, templates, **context):

        feed_name = description = (
            f"{app.theme_context.get('SITENAME')}"
            f" | {content_type.title()} | RSS feed"
        )

        if context.get('articles_page'):
            contents = context['articles_page'].object_list
        else:
            contents = context['articles']

        rss = pyrss.RSS2(
            title=feed_name,
            link=request.url_root,
            description=description,
            language=app.config.get('RSS_LANGUAGE', 'en-us'),
            copyright=app.config.get('RSS_COPYRIGHT', 'All rights reserved.'),
            lastBuildDate=datetime.now(),
            categories=[str(context.get('tag') or context.get('category'))],
        )

        # set rss.pubDate to the newest post in the collection
        # back 10 years in the past
        rss_pubdate = datetime.today() - timedelta(days=365 * 10)

        for content in contents:
            content = make_model(content)

            if content.date > rss_pubdate:
                rss_pubdate = content.date

            rss.items.append(
                pyrss.RSSItem(
                    title=content.title,
                    link=make_external_url(content.url),
                    description=cdata(content.content),
                    author=str(content.author),
                    categories=[str(content.tags)],
                    guid=hashlib.sha1(
                        content.title.encode('utf-8') +
                        content.url.encode('utf-8')
                    ).hexdigest(),
                    pubDate=content.date,
                )
            )

        # set the new published date after iterating the contents
        rss.pubDate = rss_pubdate

        return rss.to_xml(encoding=app.config.get('RSS_ENCODING', 'utf-8'))
Beispiel #4
0
    def render_rss(self, content_type, templates, **context):

        feed_name = description = (
            f"{app.theme_context.get('SITENAME')}"
            f" | {content_type.title()} | RSS feed"
        )

        if context.get('articles_page'):
            contents = context['articles_page'].object_list
        else:
            contents = context['articles']

        rss = pyrss.RSS2(
            title=feed_name,
            link=request.url_root,
            description=description,
            language=app.config.get('RSS_LANGUAGE', 'en-us'),
            copyright=app.config.get('RSS_COPYRIGHT', 'All rights reserved.'),
            lastBuildDate=datetime.now(),
            categories=[str(context.get('tag') or context.get('category'))],
        )

        # set rss.pubDate to the newest post in the collection
        # back 10 years in the past
        rss_pubdate = datetime.today() - timedelta(days=365 * 10)

        for content in contents:
            content = make_model(content)

            if content.date > rss_pubdate:
                rss_pubdate = content.date

            rss.items.append(
                pyrss.RSSItem(
                    title=content.title,
                    link=make_external_url(content.url),
                    description=cdata(content.content),
                    author=str(content.author),
                    categories=[str(content.tags)],
                    guid=hashlib.sha1(
                        content.title.encode('utf-8') +
                        content.url.encode('utf-8')
                    ).hexdigest(),
                    pubDate=content.date,
                )
            )

        # set the new published date after iterating the contents
        rss.pubDate = rss_pubdate

        return rss.to_xml(encoding=app.config.get('RSS_ENCODING', 'utf-8'))
Beispiel #5
0
 def external_url(self):
     return make_external_url(self.url)