def render_sitemap(request, sitemap_name=0, sitemap_param=0): if (sitemap_name == sitemap_param == 0): return sitemap_views.sitemap( request, {sitemap_name: ProductDetailSitemap(0, 100)}, None, 'sitemap.xml') initial = 0 if int(sitemap_param) == 1 else ((int(sitemap_param) - 1) * 50) final = 50 if int(sitemap_param) == 1 else (int(sitemap_param) * 50) return sitemap_views.sitemap( request, {sitemap_name: ProductDetailSitemap(initial, final)}, None, 'sitemap.xml')
def handle(self, *args, **options): directory = os.path.join(settings.MEDIA_ROOT, 'sitemaps') if not os.path.exists(directory): os.mkdir(directory) # make fake request r = HttpRequest() # do the sitemap index response = index(r, sitemaps) f = open(os.path.join(directory, 'sitemap.xml'), 'w') f.write(response.content) f.close() # do all of the individual sitemaps maps = re.findall(r'<loc>(.*?)</loc>', response.content) for map in maps: url = urlparse.urlparse(map) r.GET = dict(urlparse.parse_qsl(url.query)) section = url.path.split("-").pop().split(".").pop(0) filename = os.path.join(directory, url.path[1:]) if ('p' in r.GET): filename += "_p_%s" % r.GET['p'] response = sitemap(r, sitemaps, section) f = open(filename, 'w') f.write(response.content) f.close()
def generate_sitemap(self): self.log("start") sitemaps = { 'events': EventSitemap(), 'articles': ArticleSitemap(), 'net': CalendarNetSitemap(), 'simple': SimplePages() } self.log("generate sitemap") self.log( "events: {0} links".format(sitemaps['events'].paginator.count) ) self.log( "articles: {0} links".format(sitemaps['articles'].paginator.count) ) self.log( "net: {0} links".format(sitemaps['net'].paginator.count) ) self.log( "simple: {0} links".format(sitemaps['simple'].paginator.count) ) xml = sitemap(HttpRequest(), sitemaps) xml_file = open(settings.SITEMAP, 'w') self.log("write to {0}".format(settings.SITEMAP)) xml_file.write(xml.rendered_content.encode("utf-8")) xml_file.close() self.log("finish")
def custom_sitemap_index(request, sitemaps, section=None, template_name='sitemap.xml', content_type='application/xml'): platform = request.GET.get('platform', None) platform_in = request.GET.get('platform__in', None) domain = request.GET.get('domain', None) if not domain: return HttpResponseBadRequest( content='must pass in domain as a querystring argument') platform_filters = None platform_selection = platform or platform_in if platform_selection: platform_filters = platform_selection.split(',') sitemaps_copy = copy.deepcopy(sitemaps) for section, site in sitemaps_copy.items(): if callable(site): sitemaps_copy[section] = site(platform_filters=platform_filters, domain=domain) return django_sitemaps_views.sitemap(request, sitemaps_copy, None, template_name, content_type)
def create_sitemap(request): sitemap_classes = get_all_sitemaps() #print "Found %d sitemap classes" % len(sitemap_classes) #for cls in sitemap_classes: # print cls.__name__ sitemaps = dict([(cls.__name__, cls) for cls in sitemap_classes]) #print str(sitemaps) return sitemap(request, sitemaps)
def sitemap_wrapper(request, sitemaps, section): path = os.path.join(settings.MEDIA_ROOT, "sitemaps", "sitemap-%s.xml" % section) if 'p' in request.GET: path += '_p_%s' % request.GET['p'] if os.path.exists(path): return HttpResponse(open(path), mimetype='application/xml') else: return sitemap(request, sitemaps, section)
def sitemap_xml(request, *args, **kwargs): sitemaps = { 'static': StaticViewSitemap, 'posts': BlogsPostsSitemap, 'categories': BlogsCategoriesSitemap, } kwargs['sitemaps'] = sitemaps return sitemap(request, *args, **kwargs)
def cached_sitemap(request): """ generate sitemap.xml onec a day and show saved version """ sitemaps = { 'eshop_categories': ArticleCategorySitemap, 'eshop_items': ArticleItemSitemap, 'flatpages': FlatPageSitemap, } return sitemap(request, sitemaps=sitemaps)
def test_event_sitemap(request_factory: RequestFactory, event: Event, user: get_user_model()): request = request_factory.get("/sitemap.xml") request.user = user response = sitemap(request, sitemaps={'events': EventSitemap}).render() assert event.slug in response.rendered_content assert response.status_code == 200
def test_rendering_sitemaps(rf): Page = swapper.load_model('varlet', 'Page') pages = [Page.objects.create(url=str(x), template="varlet/pages/layouts/test_template.html") for x in range(1, 5)] sm = PageSitemap() response = sitemap(rf.get('/'), sitemaps={'pages': sm}) response.render() assert '<loc>http://example.com/3/</loc>' in force_text(response.content) assert '<loc>http://example.com/2/</loc>' in force_text(response.content) assert '<loc>http://example.com/1/</loc>' in force_text(response.content)
def test_static_sitemap(request_factory: RequestFactory, user: get_user_model()): request = request_factory.get("/sitemap.xml") request.user = user response = sitemap(request, sitemaps={'static': StaticSitemap}).render() assert reverse('contact:contact') in response.rendered_content assert response.status_code == 200
def test_page_sitemap(request_factory: RequestFactory, page: Page, user: get_user_model()): request = request_factory.get("/sitemap.xml") request.user = user response = sitemap(request, sitemaps={'pages': PageSitemap}).render() assert page.slug in response.rendered_content assert response.status_code == 200
def sitemap_html(request, *args, **kwargs): sitemaps = { 'static': StaticViewSitemap, 'posts': BlogsPostsSitemap, 'categories': BlogsCategoriesSitemap, } kwargs['sitemaps'] = sitemaps kwargs['template_name'] = 'sitemap.html' kwargs['content_type'] = None return sitemap(request, *args, **kwargs)
def sitemap_section( self, request, node=None, competition=None, season=None, division=None, *args, **kwargs, ): # We need to "pop" the node keyword argument return sitemaps_views.sitemap(request, *args, **kwargs)
def return_sitemap(request: HttpRequest) -> HttpResponse: """ View that returns the sitemap for the site. :param request: The incoming HTTP request. :return: The HTTP response to return to the user. """ response = sitemap(request, sitemaps) response.render() response.content = response.content.replace( b"http://dory.creait.mun.ca", b"https://issfcloud.toobigtoignore.net") return response
def cached_sitemap(request): """ generate simap.xml onec a day and show saved version """ sitemap_filename = os.path.join(settings.PROJECT_ROOT, 'sitemap.xml') if os.path.exists(sitemap_filename) and (date.fromtimestamp(os.path.getmtime(sitemap_filename)) - date.today()) < timedelta(days=1): with open(sitemap_filename, "r") as sitemap_file: raw_data = HttpResponse(sitemap_file.read(), mimetype="text/xml") else: sitemaps = { 'eshop_categories' : ArticleCategorySitemap, 'eshop_items' : ArticleItemSitemap, } raw_data = sitemap(request, sitemaps=sitemaps) with open(sitemap_filename, "w") as sitemap_file: sitemap_file.write(raw_data.content) return raw_data
def test_sitemap(six_posts): from main.sitemap import SluggedViewSiteMap path = reverse('sitemap') request = RequestFactory().get(path) sitemaps = { 'slugged': SluggedViewSiteMap, } response = sitemap(request, sitemaps=sitemaps) assert response.status_code == 200 assert '<loc>http://testserver/about/</loc>' in response.rendered_content assert '<loc>http://testserver/other/2018-04-15/slug-4/</loc>' in response.rendered_content
def my_sitemap(request,**kwargs): from django.contrib.sitemaps.views import sitemap blog_dict = { 'queryset': BlogPost.objects.published(), 'date_field': 'created', } page_dict = { 'queryset': RichTextPage.objects.published(), } sitemaps = { 'pages': GenericSitemap(page_dict, priority = 0.8, changefreq = "always"), 'blog': GenericSitemap(blog_dict, priority=0.6, changefreq = "always"), } return sitemap(request,sitemaps)
def my_sitemap(request, **kwargs): from django.contrib.sitemaps.views import sitemap blog_dict = { 'queryset': BlogPost.objects.published(), 'date_field': 'created', } page_dict = { 'queryset': RichTextPage.objects.published(), } sitemaps = { 'pages': GenericSitemap(page_dict, priority=0.8, changefreq="always"), 'blog': GenericSitemap(blog_dict, priority=0.6, changefreq="always"), } return sitemap(request, sitemaps)
def test_blog_sitemap(self): sitemaps = { 'blog': BlogSitemap, } request = self.factory.get('/blog/rss/') request.user = self.user self.assertRaises( Exception, sitemap, request, sitemaps ) sitemaps = { 'blog': BlogSitemap(url_name="blog-single"), } response = sitemap(request, sitemaps) self.assertEqual(response.status_code, 200)
def handle_noargs(self, **options): h = HttpRequest() s = sitemap(h, sitemaps=sitemaps) f = open(os.path.join(settings.MEDIA_ROOT, 'sitemap.xml'), 'wt') f.write(s.content) f.close()
def sitemap(request): return sitemap_views.sitemap(request, sitemaps={"weblog": WeblogSitemap, "flatpages": FlatPageSitemap})
def sitemap(request, section=None, template_name='sitemap.xml', mimetype='application/xml'): from django.contrib.sitemaps.views import sitemap return sitemap(request, sitemaps, section, template_name, mimetype)
def sitemap_with_images(request, sitemaps, section=None, content_type='application/xml'): return sitemap(request, sitemaps, section, 'sitemap/sitemap.xml', content_type)
def sitemap(request, **kwargs): sitemaps = {'wagtail': MoloSitemap(request)} return sitemap_views.sitemap(request, sitemaps, **kwargs)
def subdomain_sitemap(request, username, section, sitemaps): return sitemap(request, sitemaps)
def sitemap_view(request): return views.sitemap(request, sitemaps)
def sitemap(request): return sitemap_views.sitemap(request, sitemaps={ 'weblog': WeblogSitemap, 'flatpages': FlatPageSitemap, })
def sitemap(request, sitemaps=None, **kwargs): if sitemaps: sitemaps = prepare_sitemaps(request, sitemaps) else: sitemaps = {'wagtail': Sitemap(request)} return sitemap_views.sitemap(request, sitemaps, **kwargs)
def unicms_sitemap(request): unicms_sitemap = base_unicms_sitemap(request) sitemaps = sitemap(request, sitemaps=unicms_sitemap) return HttpResponse(sitemaps.render(), content_type='text/xml')
def sitemap(request, sitemaps=None, **kwargs): if sitemaps: sitemaps = prepare_sitemaps(request, sitemaps) else: sitemaps = {'tuiuiu': Sitemap(request.site)} return sitemap_views.sitemap(request, sitemaps, **kwargs)
def handle_noargs(self, **options): h = HttpRequest() s = sitemap(h, sitemaps=sitemaps) f = open(os.path.join(settings.MEDIA_ROOT, "sitemap.xml"), "wt") f.write(s.content) f.close()
def sitemap_view_2(request): sitemaps_ = { 'static': StaticViewSitemap, } return sitemap(request=request, sitemaps=sitemaps_)