當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。