当前位置: 首页>>代码示例>>Python>>正文


Python sitemaps.GenericSitemap类代码示例

本文整理汇总了Python中django.contrib.sitemaps.GenericSitemap的典型用法代码示例。如果您正苦于以下问题:Python GenericSitemap类的具体用法?Python GenericSitemap怎么用?Python GenericSitemap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GenericSitemap类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_sitemaps

def build_sitemaps():
    sitemap_element = "<sitemap><loc>%s</loc><lastmod>%s</lastmod></sitemap>"
    sitemap_index = "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"
    for locale in settings.MDN_LANGUAGES:
        queryset = (Document.objects
                        .filter(is_template=False, locale=locale)
                        .exclude(title__startswith='User:')
                        .exclude(title__iregex=r'Redirect [0-9]+$')
                        .exclude(html__iregex=r'^(<p>)?(#)?REDIRECT')
                        .exclude(slug__icontains='Talk:')
                   )
        if len(queryset) > 0:
            info = {'queryset': queryset, 'date_field': 'modified'}
            sitemap = GenericSitemap(info, priority=0.5)
            urls = sitemap.get_urls(page=1)
            xml = smart_str(loader.render_to_string('sitemap.xml',
                                                    {'urlset': urls}))
            xml = xml.replace('http://', 'https://')
            directory = '%s/sitemaps/%s' % (settings.MEDIA_ROOT, locale)
            if not os.path.exists(directory):
                os.makedirs(directory)
            f = open('%s/sitemap.xml' % directory, 'w')
            f.write(xml)
            f.close()

            sitemap_url = ("https://%s/sitemaps/%s/sitemap.xml" % (
                Site.objects.get_current().domain, locale))
            sitemap_index = sitemap_index + sitemap_element % (sitemap_url,
                time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime()))

    sitemap_index = sitemap_index + "</sitemapindex>"
    index_file = open('%s/sitemap.xml' % settings.MEDIA_ROOT, 'w')
    index_file.write(parseString(sitemap_index).toxml())
    index_file.close()
开发者ID:azhar2005,项目名称:kuma,代码行数:34,代码来源:cron.py

示例2: __init__

 def __init__(self, info_dict, priority=None, changefreq=None):
     GenericSitemap.__init__(self,
                             info_dict,
                             priority=priority,
                             changefreq=changefreq)
     self.url = info_dict.get('url', '/')
     self.slugfield = info_dict['slugfield']
     self.suffix = info_dict.get('suffix', '')
开发者ID:okfish,项目名称:django-periodicals,代码行数:8,代码来源:sitemaps.py

示例3: test_sitemap_item

 def test_sitemap_item(self):
     """
     Check to make sure that the raw item is included with each
     Sitemap.get_url() url result.
     """
     user_sitemap = GenericSitemap({'queryset': User.objects.all()})
     def is_user(url):
         return isinstance(url['item'], User)
     item_in_url_info = all(map(is_user, user_sitemap.get_urls()))
     self.assertTrue(item_in_url_info)
开发者ID:15580056814,项目名称:hue,代码行数:10,代码来源:http.py

示例4: test_sitemap_item

    def test_sitemap_item(self):
        """
        Check to make sure that the raw item is included with each
        Sitemap.get_url() url result.
        """
        test_sitemap = GenericSitemap({'queryset': TestModel.objects.order_by('pk').all()})

        def is_testmodel(url):
            return isinstance(url['item'], TestModel)
        item_in_url_info = all(map(is_testmodel, test_sitemap.get_urls()))
        self.assertTrue(item_in_url_info)
开发者ID:756613351,项目名称:django,代码行数:11,代码来源:test_http.py

示例5: generate

def generate():
    sitemap = GenericSitemap({'queryset': models.Post.objects.filter(type__in=const.POST_TOPLEVEL).exclude(type=const.POST_BLOG), })
    urlset = sitemap.get_urls()
    text = loader.render_to_string('sitemap.xml', {'urlset': urlset})
    text = smart_str(text)
    site = Site.objects.get_current()
    fname = path(settings.EXPORT_DIR, 'sitemap.xml')
    print '*** writing sitemap for %s to %s' % (site, fname)
    fp = open(fname, 'wt')
    fp.write(text)
    fp.close()
    print '*** done'
开发者ID:amnuay,项目名称:biostar-central,代码行数:12,代码来源:sitemap.py

示例6: generate_sitemap

def generate_sitemap():
    sitemap = GenericSitemap({
        'queryset': Post.objects.filter(type__in=Post.TOP_LEVEL).exclude(type=Post.BLOG),
    })
    urlset = sitemap.get_urls()
    text = loader.render_to_string('sitemap.xml', {'urlset': urlset})
    text = smart_str(text)
    site = Site.objects.get_current()
    fname = path(settings.STATIC_ROOT, 'sitemap.xml')
    logger.info('*** writing sitemap for %s to %s' % (site, fname))
    fp = open(fname, 'wt')
    fp.write(text)
    fp.close()
    logger.info('*** done')
开发者ID:Himanshu1495,项目名称:biostar-central,代码行数:14,代码来源:sitemap.py

示例7: location

 def location(self, obj):
     url = GenericSitemap.location(self, obj)
     return "%s%s" % (url, self.suffix)
开发者ID:okfish,项目名称:django-periodicals,代码行数:3,代码来源:sitemaps.py


注:本文中的django.contrib.sitemaps.GenericSitemap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。