예제 #1
0
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')
예제 #2
0
    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()
예제 #3
0
 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")
예제 #4
0
 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()
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
파일: sitemaps.py 프로젝트: strogo/brisket
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)
예제 #8
0
def sitemap_xml(request, *args, **kwargs):
    sitemaps = {
        'static': StaticViewSitemap,
        'posts': BlogsPostsSitemap,
        'categories': BlogsCategoriesSitemap,
    }
    kwargs['sitemaps'] = sitemaps
    return sitemap(request, *args, **kwargs)
예제 #9
0
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)
예제 #10
0
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)
예제 #11
0
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
예제 #12
0
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)
예제 #13
0
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
예제 #14
0
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
예제 #15
0
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)
예제 #16
0
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)
예제 #17
0
파일: sites.py 프로젝트: goodtune/vitriolic
 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)
예제 #18
0
파일: urls.py 프로젝트: toobigtoignore/issf
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
예제 #19
0
파일: views.py 프로젝트: hnejadi/technostar
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
예제 #21
0
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)
예제 #22
0
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)
예제 #23
0
    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)
예제 #24
0
 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()
예제 #25
0
def sitemap(request):
    return sitemap_views.sitemap(request, sitemaps={"weblog": WeblogSitemap, "flatpages": FlatPageSitemap})
예제 #26
0
파일: views.py 프로젝트: jatinS-dev/web-1
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)
예제 #27
0
def sitemap_with_images(request,
                        sitemaps,
                        section=None,
                        content_type='application/xml'):
    return sitemap(request, sitemaps, section, 'sitemap/sitemap.xml',
                   content_type)
예제 #28
0
def sitemap(request, **kwargs):
    sitemaps = {'wagtail': MoloSitemap(request)}
    return sitemap_views.sitemap(request, sitemaps, **kwargs)
예제 #29
0
파일: sitemap.py 프로젝트: thuvh/filmmaster
def subdomain_sitemap(request, username, section, sitemaps):
    return sitemap(request, sitemaps)
예제 #30
0
def sitemap_view(request):
    return views.sitemap(request, sitemaps)
예제 #31
0
def sitemap(request):
    return sitemap_views.sitemap(request, sitemaps={
        'weblog': WeblogSitemap,
        'flatpages': FlatPageSitemap,    
    })
예제 #32
0
파일: views.py 프로젝트: petschna/linux-day
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)
예제 #33
0
def unicms_sitemap(request):
    unicms_sitemap = base_unicms_sitemap(request)
    sitemaps = sitemap(request, sitemaps=unicms_sitemap)
    return HttpResponse(sitemaps.render(), content_type='text/xml')
예제 #34
0
def subdomain_sitemap(request, username, section, sitemaps):
    return sitemap(request, sitemaps)
예제 #35
0
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)
예제 #36
0
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)
예제 #37
0
 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()
예제 #38
0
def sitemap_view_2(request):
    sitemaps_ = {
        'static': StaticViewSitemap,
    }
    return sitemap(request=request, sitemaps=sitemaps_)
예제 #39
0
def sitemap(request):
    return sitemap_views.sitemap(request,
                                 sitemaps={
                                     'weblog': WeblogSitemap,
                                     'flatpages': FlatPageSitemap,
                                 })