示例#1
0
    def get(self):

        urls = []

        def addurl(loc, lastmod=None, changefreq=None, priority=None):
            url_info = {
                'location': loc,
                'lastmod': lastmod,
                'changefreq': changefreq,
                'priority': priority,
            }
            urls.append(url_info)

        addurl(g_blog.baseurl, changefreq='daily', priority=1)

        entries = Entry.all().filter('published =', True).order('-date').fetch(g_blog.sitemap_entries)

        for item in entries:
            loc = '%s/%s' % (g_blog.baseurl, item.link)
            addurl(loc, item.date, 'daily', 0.9)

        if g_blog.sitemap_include_category:
            cats = Category.all()
            for cat in cats:
                loc = '%s/category/%s' % (g_blog.baseurl, cat.slug)
                addurl(loc, None, 'weekly', 0.8)

        if g_blog.sitemap_include_tag:
            tags = Tag.all()
            for tag in tags:
                loc = '%s/tag/%s' % (g_blog.baseurl, urlencode(tag.tag))
                addurl(loc, None, 'weekly', 0.8)

        self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
        self.render2('views/sitemap.xml', {'urlset': urls})
示例#2
0
    def get(self, tags=None):
        entries = Entry.all().order('-date')
        cates = Category.all()
        tags = Tag.all()

        self.response.headers['Content-Type'] = 'binary/octet-stream'  # 'application/atom+xml'
        self.render2('views/wordpress.xml', {'entries': entries, 'cates': cates, 'tags': tags})
示例#3
0
    def action_update_tags(self, slug=None):
        for tag in Tag.all():
            tag.delete()
        for entry in Entry.all().filter('entrytype =', 'post'):
            if entry.tags:
                for t in entry.tags:
                    try:
                        logging.info('sss:' + t)
                        Tag.add(t)
                    except:
                        traceback.print_exc()

        self.write('"All tags for entry have been updated."')
示例#4
0
    def initialize(self, request, response):
        try:
            BaseRequestHandler.initialize(self, request, response)

            m_pages = (
                Entry.all()
                .filter("entrytype =", "page")
                .filter("published =", True)
                .filter("entry_parent =", 0)
                .order("menu_order")
            )
            blogroll = Link.all().filter("linktype =", "blogroll")

            query = Entry.gql("WHERE entrytype = 'post' AND published = TRUE ORDER BY date")
            entries = query.fetch(1)
            start_date = end_date = None
            if entries:
                start_date = entries[0].date

            query = Entry.gql("WHERE entrytype = 'post' AND published = TRUE ORDER BY date DESC")
            entries = query.fetch(1)
            if entries:
                end_date = entries[0].date

            end_year = 0
            if end_date:
                end_year = end_date.year

            self.template_vals.update(
                {
                    "dates": self.build_dates(start_date, end_date),
                    "end_year": end_year,
                    "menu_pages": m_pages,
                    "tags": Tag.all().order("tag"),
                    "blogroll": blogroll,
                    "recent_comments": Comment.all().order("-date").fetch(5),
                }
            )
            logging.info("base public page initialized")
        except:
            logging.error(traceback.format_exc())
            return self.error(404)