def __init__(self, verbosity): self.verbosity = verbosity self.has_changes = False self.storage = _lazy_load(conf.STORAGE_CLASS)(location='/') self.sitemaps = _lazy_load(conf.ROOT_SITEMAP) if not isinstance(self.sitemaps, dict): self.sitemaps = dict(enumerate(self.sitemaps))
def __init__(self, verbosity): self.verbosity = verbosity self.has_changes = False self.storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR) self.sitemaps = _lazy_load(conf.ROOT_SITEMAP) if not isinstance(self.sitemaps, dict): self.sitemaps = dict(enumerate(self.sitemaps))
def __init__(self, verbosity, root_dir=None, base_url=None, language=None): self.verbosity = verbosity self.has_changes = False self.base_url = conf.get_url() if base_url is None else base_url self.root_dir = conf.ROOT_DIR if root_dir is None else root_dir self.language = conf.LANGUAGE if language is None else language try: self.storage = _lazy_load( conf.STORAGE_CLASS)(location=self.root_dir) except TypeError: self.storage = _lazy_load(conf.STORAGE_CLASS)() self.sitemaps = _lazy_load(conf.ROOT_SITEMAP) if not isinstance(self.sitemaps, dict): self.sitemaps = dict(enumerate(self.sitemaps))
def sitemapSectionZipped(request, section): storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR) path = os.path.join(conf.ROOT_DIR, 'sitemap-{}.xml.gz'.format(section)) f = storage.open(path) content = f.readlines() f.close() return HttpResponse(content, content_type='application/zip')
def get(self, request, *args, **kwargs): section = kwargs.get('section') try: storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR) except TypeError: storage = _lazy_load(conf.STORAGE_CLASS)() path = os.path.join(conf.ROOT_DIR, '{}.xml'.format(section)) if not storage.exists(path): raise Http404('No sitemap file found on %r. Run django-admin.py ' 'refresh_sitemap first.' % path) f = storage.open(path) content = f.readlines() f.close() return HttpResponse(content, content_type='application/xml')
def write_index(self): storage = _lazy_load(conf.STORAGE_CLASS)() sitemaps = _lazy_load(conf.ROOT_SITEMAP) url = self.normalize_url(conf.URL) parts = [] if not isinstance(sitemaps, dict): sitemaps = dict(enumerate(sitemaps)) for section, site in sitemaps.items(): if callable(site): pages = site().paginator.num_pages else: pages = site.paginator.num_pages for page in range(1, pages + 1): filename = conf.FILENAME_TEMPLATE % {'section': section, 'page': page} lastmod = self.write_page(site, page, filename, storage) if conf.USE_GZIP: filename += '.gz' parts.append({ 'location': '%s%s' % (url, filename), 'lastmod': lastmod }) name = os.path.join(conf.ROOT_DIR, 'sitemap.xml') if storage.exists(name): storage.delete(name) output = loader.render_to_string(conf.INDEX_TEMPLATE, {'sitemaps': parts}) buf = StringIO() buf.write(output) buf.seek(0) storage.save(name, buf) if conf.PING_GOOGLE: try: sitemap_url = reverse('static_sitemaps_index') except NoReverseMatch: sitemap_url = "%ssitemap.xml" % url ping_google(sitemap_url)
def serve_index(request): storage = _lazy_load(conf.STORAGE_CLASS)() path = os.path.join(conf.ROOT_DIR, 'sitemap.xml') if not storage.exists(path): raise Http404('No sitemap index file found on %r. Run django-admin.py ' 'refresh_sitemap first.' % path) f = storage.open(path) content = f.readlines() f.close() return HttpResponse(content, content_type='application/xml')
def serve_index(request): storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR) path = os.path.join(conf.ROOT_DIR, 'sitemap.xml') if not storage.exists(path): raise Http404('No sitemap index file found on %r. Run django-admin.py ' 'refresh_sitemap first.' % path) f = storage.open(path) content = f.readlines() f.close() return HttpResponse(content, content_type='application/xml')
def __init__(self, verbosity, site=None): self.site = site if site is not None else SitemapGenerator.get_default_site( ) self.protocol = conf.MOCK_SITE_PROTOCOL if conf.MOCK_SITE else conf.FORCE_PROTOCOL self.verbosity = verbosity self.has_changes = False self.storage = get_storage(self.site) self.sitemaps = _lazy_load(conf.ROOT_SITEMAP) if not isinstance(self.sitemaps, dict): self.sitemaps = dict(enumerate(self.sitemaps))
def sitemap_section_zipped(request, section): storage = _lazy_load(conf.STORAGE_CLASS)(location=conf.ROOT_DIR) path = os.path.join(conf.ROOT_DIR, 'sitemap-{}.xml.gz'.format(section)) try: f = storage.open(path) except FileNotFoundError: raise Http404("{0} does not exist".format(section)) content = f.readlines() f.close() return HttpResponse(content, content_type='application/zip')