Additional arguments for url lookup in sitemap index

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Additional arguments for url lookup in sitemap index

Sandro Covo
Hello,

I'm trying to add sitemaps on a per object base to my project. I have created a wrapper around sitemaps.views.sitemap that captures additional parameters to get the object and create the required sitemap. But I can't create a sitemap index, since the index views tries to resolve the sitemap view with only the section parameter.

The solution would be to allow additional parameters to the sitemaps.views.index function that would be used in the lookup for the section-urls. I created a branch and tried to implement this here: https://github.com/django/django/commit/d4ee80daabcf9af4e7cfe6b966522849e8018224

Not sure how to proceed from here, if you think that's ok I think I'll create a pull request?

Best regards
Sandro

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/b74b4fe0-3479-4363-8169-0d5fe2ac122a%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Additional arguments for url lookup in sitemap index

Adam Johnson-2
I'm trying to add sitemaps on a per object base to my project.

Can you explain this a little more? I don't follow what sitemap structure you're pursuing that's different to the default, nor why.

On Tue, 26 May 2020 at 09:24, Sandro Covo <[hidden email]> wrote:
Hello,

I'm trying to add sitemaps on a per object base to my project. I have created a wrapper around sitemaps.views.sitemap that captures additional parameters to get the object and create the required sitemap. But I can't create a sitemap index, since the index views tries to resolve the sitemap view with only the section parameter.

The solution would be to allow additional parameters to the sitemaps.views.index function that would be used in the lookup for the section-urls. I created a branch and tried to implement this here: https://github.com/django/django/commit/d4ee80daabcf9af4e7cfe6b966522849e8018224

Not sure how to proceed from here, if you think that's ok I think I'll create a pull request?

Best regards
Sandro

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/b74b4fe0-3479-4363-8169-0d5fe2ac122a%40googlegroups.com.


--
Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM2TzZDfi0%2BnYAMLS7KEYdau-ENkfevHCpXMv4uwueoriQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Additional arguments for url lookup in sitemap index

Sandro Covo
In reply to this post by Sandro Covo
Sure, my urls look like this:
urlpatterns = (
    path
('<path:path>/', views.page_detail, name="page"),
    path
('<path:path>/sitemap.xml', cache_page(60*60)(views.sitemap_view),
         name
="sitemap-index"),
)

And i have this view for the sitemap_view, that creates the sitemap for each page under the path of the request.

def sitemap_view(request, path='/'):
    sitemaps
= {}

    top_page
= get_object_or_404(
       
Page.objects.active(),
        path
=f"/{path}/" if path else '/',
   
)

    sitemaps
['pages'] = PageSitemap(top_page)

   
for blog_page in top_page.descendants(include_self=True).filter(application='blog'):
        sitemaps
[blog_page.slug] = ArticleSitemap(blog_page)

   
for event_page in top_page.descendants(include_self=True).filter(application='events'):
        sitemaps
[event_page.slug] = EventSitemap(event_page)

   
for category_page in top_page.descendants(include_self=True).filter(application='categories'):
        sitemaps
[category_page.slug] = CategorySitemap(category_page)

   
return sitemap_view(
        request
, sitemaps,
   
)

So under one path lives a seperate structure that has different content.


On Tuesday, May 26, 2020 at 2:33:42 PM UTC+2, Sandro Covo wrote:
Hello,

I'm trying to add sitemaps on a per object base to my project. I have created a wrapper around sitemaps.views.sitemap that captures additional parameters to get the object and create the required sitemap. But I can't create a sitemap index, since the index views tries to resolve the sitemap view with only the section parameter.

The solution would be to allow additional parameters to the sitemaps.views.index function that would be used in the lookup for the section-urls. I created a branch and tried to implement this here: <a href="https://github.com/django/django/commit/d4ee80daabcf9af4e7cfe6b966522849e8018224" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2Fd4ee80daabcf9af4e7cfe6b966522849e8018224\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHfBb6m2GlluZaBVJq0jEZsNMK-tQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fcommit%2Fd4ee80daabcf9af4e7cfe6b966522849e8018224\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHfBb6m2GlluZaBVJq0jEZsNMK-tQ&#39;;return true;">https://github.com/django/django/commit/d4ee80daabcf9af4e7cfe6b966522849e8018224

Not sure how to proceed from here, if you think that's ok I think I'll create a pull request?

Best regards
Sandro

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/7791e496-e225-4dca-a57b-fca9851c34db%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Additional arguments for url lookup in sitemap index

Adam Johnson-2
Oh I see. I think your sitemap structure is quite different to what Django's sitemaps index is intended for. I think it's probably better that you create your own index view based copy-pasting the built-in one, rather than adding extra parameters to it. It's not much code, and Django can't be infinitely flexible.

On Tue, 26 May 2020 at 14:34, Sandro Covo <[hidden email]> wrote:
Sure, my urls look like this:
urlpatterns = (
    path
('<path:path>/', views.page_detail, name="page"),
    path
('<path:path>/sitemap.xml', cache_page(60*60)(views.sitemap_view),
         name
="sitemap-index"),
)

And i have this view for the sitemap_view, that creates the sitemap for each page under the path of the request.

def sitemap_view(request, path='/'):
    sitemaps
= {}

    top_page
= get_object_or_404(
       
Page.objects.active(),
        path
=f"/{path}/" if path else '/',
   
)

    sitemaps
['pages'] = PageSitemap(top_page)

   
for blog_page in top_page.descendants(include_self=True).filter(application='blog'):
        sitemaps
[blog_page.slug] = ArticleSitemap(blog_page)

   
for event_page in top_page.descendants(include_self=True).filter(application='events'):
        sitemaps
[event_page.slug] = EventSitemap(event_page)

   
for category_page in top_page.descendants(include_self=True).filter(application='categories'):
        sitemaps
[category_page.slug] = CategorySitemap(category_page)

   
return sitemap_view(
        request
, sitemaps,
   
)

So under one path lives a seperate structure that has different content.


On Tuesday, May 26, 2020 at 2:33:42 PM UTC+2, Sandro Covo wrote:
Hello,

I'm trying to add sitemaps on a per object base to my project. I have created a wrapper around sitemaps.views.sitemap that captures additional parameters to get the object and create the required sitemap. But I can't create a sitemap index, since the index views tries to resolve the sitemap view with only the section parameter.

The solution would be to allow additional parameters to the sitemaps.views.index function that would be used in the lookup for the section-urls. I created a branch and tried to implement this here: https://github.com/django/django/commit/d4ee80daabcf9af4e7cfe6b966522849e8018224

Not sure how to proceed from here, if you think that's ok I think I'll create a pull request?

Best regards
Sandro

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/7791e496-e225-4dca-a57b-fca9851c34db%40googlegroups.com.


--
Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM09kJ5Anf8wRdPuKjKRtKK-ikYnHTxPB_RL6a7Ubt2%3DuA%40mail.gmail.com.