Пример #1
0
    def make_atom(self, feed_name, contents):
        feed = AtomFeed(
            feed_name,
            feed_url=request.url,
            url=request.url_root
        )
        for content in contents:
            if not content.channel.include_in_rss:
                continue

            if content.created_by:
                author = content.created_by.name
            else:
                author = Config.get('site', 'site_author', '')

            feed.add(
                content.title,
                cdata(content.get_text()),
                content_type="html",
                author=author,
                url=self.make_external_url(content.get_absolute_url()),
                updated=content.updated_at,
                published=content.created_at
            )
        return feed
Пример #2
0
    def get(self, tag):
        contents = self.get_contents(tag)
        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(Config.get("site", "site_name", ""), "Tag {0}".format(tag))
        feed = self.make_atom(feed_name, contents)

        return feed.get_response()
Пример #3
0
    def get(self, long_slug):
        contents = self.get_contents(long_slug)
        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(Config.get("site", "site_name", ""), self.channel.title)
        feed = self.make_atom(feed_name, contents)

        return feed.get_response()
Пример #4
0
    def make_rss(self, feed_name, contents):
        conf = current_app.config

        if not self.channel:  # Feed view
            description = 'Articles with tag: ' + self.tag
            categories = [self.tag]

        else:                # Tag View
            description = self.channel.get_text()
            categories = self.channel.tags

        rss = pyrss.RSS2(
            title=feed_name,
            link=request.url_root,
            # channel description after markdown processing
            description=description,
            language=conf.get('RSS_LANGUAGE', 'en-us'),
            copyright=conf.get('RSS_COPYRIGHT', 'All rights reserved.'),
            lastBuildDate=datetime.now(),
            categories=categories,
        )

        # 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:
            if not content.channel.include_in_rss:
                continue

            if content.created_at > rss_pubdate:
                rss_pubdate = content.created_at

            if content.created_by:
                author = content.created_by.name
            else:
                author = Config.get('site', 'site_author', '')

            rss.items.append(
                pyrss.RSSItem(
                    title=content.title,
                    link=content.get_absolute_url(),
                    description=content.get_text(),
                    author=author,
                    categories=content.tags,
                    guid=hashlib.sha1(
                        content.title + content.get_absolute_url()
                    ).hexdigest(),
                    pubDate=content.created_at,
                )
            )

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

        return rss.to_xml(encoding=conf.get('RSS_ENCODING', 'utf-8'))
Пример #5
0
    def get(self, tag):
        contents = self.get_contents(tag)
        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(
            Config.get('site', 'site_name', ''), "Tag {0}".format(tag))
        feed = self.make_atom(feed_name, contents)

        return feed.get_response()
Пример #6
0
    def get(self, long_slug):
        contents = self.get_contents(long_slug)
        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(
            Config.get('site', 'site_name', ''), self.channel.title)
        feed = self.make_atom(feed_name, contents)

        return feed.get_response()
Пример #7
0
def get_site_url():
    from quokka.core.models import Config
    try:
        from_site_config = Config.get('site', 'site_domain', None)
        from_settings = get_setting_value('SERVER_NAME', None)
        if from_settings and not from_settings.startswith('http'):
            from_settings = 'http://%s/' % from_settings
        return from_site_config or from_settings or request.url_root
    except RuntimeError:
        return 'http://localhost/'
Пример #8
0
    def get(self, tag):
        contents = self.get_contents(tag)
        self.channel = None

        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(Config.get("site", "site_name", ""), "Tag {0}".format(tag))

        return self.make_rss(feed_name, contents)
Пример #9
0
    def get(self, tag):
        contents = self.get_contents(tag)
        self.channel = None

        if current_app.config.get('PAGINATION_ENABLED', True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(
            Config.get('site', 'site_name', ''), "Tag {0}".format(tag))

        return self.make_rss(feed_name, contents)
Пример #10
0
    def make_rss(self, feed_name, contents):
        conf = current_app.config

        if not self.channel:  # Feed view
            description = 'Articles with tag: ' + self.tag
            categories = [self.tag]

        else:  # Tag View
            description = self.channel.get_text()
            categories = self.channel.tags

        rss = pyrss.RSS2(
            title=feed_name,
            link=request.url_root,
            # channel description after markdown processing
            description=description,
            language=conf.get('RSS_LANGUAGE', 'en-us'),
            copyright=conf.get('RSS_COPYRIGHT', 'All rights reserved.'),
            lastBuildDate=datetime.now(),
            categories=categories,
        )

        # 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:
            if not content.channel.include_in_rss:
                continue

            if content.created_at > rss_pubDate:
                rss_pubDate = content.created_at

            if content.created_by:
                author = content.created_by.name
            else:
                author = Config.get('site', 'site_author', '')

            rss.items.append(
                pyrss.RSSItem(
                    title=content.title,
                    link=content.get_absolute_url(),
                    description=content.get_text(),
                    author=author,
                    categories=content.tags,
                    guid=hashlib.sha1(content.title +
                                      content.get_absolute_url()).hexdigest(),
                    pubDate=content.created_at,
                ))

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

        return rss.to_xml(encoding=conf.get('RSS_ENCODING', 'utf-8'))
Пример #11
0
    def get(self, long_slug):
        # instantiates the self.channel property
        contents = self.get_contents(long_slug)
        self.tag = None

        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(Config.get("site", "site_name", ""), self.channel.title)

        return self.make_rss(feed_name, contents)
Пример #12
0
    def get(self, long_slug):
        # instantiates the self.channel property
        contents = self.get_contents(long_slug)
        self.tag = None

        if current_app.config.get("PAGINATION_ENABLED", True):
            contents = contents.items

        feed_name = u"{0} | {1} | feed".format(
            Config.get('site', 'site_name', ''), self.channel.title)

        return self.make_rss(feed_name, contents)
Пример #13
0
    def make_atom(self, feed_name, contents):
        feed = AtomFeed(feed_name, feed_url=request.url, url=request.url_root)
        for content in contents:
            if not content.channel.include_in_rss:
                continue

            if content.created_by:
                author = content.created_by.name
            else:
                author = Config.get('site', 'site_author', '')

            feed.add(content.title,
                     cdata(content.get_text()),
                     content_type="html",
                     author=author,
                     url=self.make_external_url(content.get_absolute_url()),
                     updated=content.updated_at,
                     published=content.created_at)
        return feed
Пример #14
0
 def test_has_default_theme(self):
     from quokka.core.models import Config
     self.assertTrue(Config.get('settings', 'DEFAULT_THEME') == 'pure')
Пример #15
0
 def test_has_default_theme(self):
     from quokka.core.models import Config
     self.assertTrue(Config.get('settings', 'DEFAULT_THEME') == 'default')
Пример #16
0
    def test_has_default_theme(self):
        from quokka.core.models import Config

        self.assertTrue(Config.get("settings", "DEFAULT_THEME") == "default")