Django sitemap index with paged content

I was working on the sitemap index. I would like every 40000 item group into one sitemap on the site index like this

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <sitemap>
        <loc>http://terrywong.co.uk/sitemap-Page1.xml</loc>
    </sitemap>
    <sitemap>
        <loc>http://terrywong.co.uk/sitemap-static.xml</loc>
    </sitemap>
    <sitemap>
        <loc>http://terrywong.co.uk/sitemap-Page3.xml</loc>
    </sitemap>
    <sitemap>
        <loc>http://terrywong.co.uk/sitemap-Page2.xml</loc>
    </sitemap>
</sitemapindex>

I couldn’t find ways of doing it without using plugin.

Each item on the siteindex require it’s own class, so I created class dynamically using type, and by using paginator

urls.py

from sitemap import generateSitemaps

sitemaps = generateSitemaps()

urlpatterns += patterns('django.contrib.sitemaps.views',
    url(r'^sitemap\.xml$', 'index', {'sitemaps': sitemaps}),
    url(r'^sitemap-(?P<section>.+)\.xml$', 'sitemap', {'sitemaps': sitemaps}),
)

sitemap.py

from models import Post
from django.core.paginator import Paginator

sitemapEntryPage=40000

def items(self):
    posts = Post.objects.filter(deletedByAdmin=False, deletedByUser=False).order_by("-id")
    paginator = Paginator(posts, sitemapEntryPage)
    return paginator.page(self.page).object_list

def generateSitemaps():
    siteMaps = { "static" : StaticViewSitemap }
    
    postPages = range(Post.objects.filter(deletedByAdmin=False, deletedByUser=False).count())[0::sitemapEntryPage]
    
    for postPage in postPages: 
        page = postPage / sitemapEntryPage + 1
        postPageCls = type('postPage' + str(page), (Sitemap,), {'items': items})
        postPageCls.page = page
        postPageCls.priority = 0.5
        postPageCls.changefreq = 'daily'
        siteMaps['postPage' + str(page)] = postPageCls

    return siteMaps

If there is a better way please feel free to let me know :)

Prince Harry’s naked Las Vegas

Not quite sure what is the fuss is about, if it’s you and me it’s would have been unnoticed anyway…

Harry

reference:

http://travelblog.dailymail.co.uk/2012/08/prince-harrys-naked-las-vegas-romp-why-everyone-royals-included-should-visit-splendid-sin-city-at-le.html

Well done Team GB

According to this news average £4.5 million investment for each Olympic Medal, individual sports is clearly cheaper than team sports, does it mean we should give up all the team sports? It is wrong to put a price on sports, nevertheless, well done to Team GB!

http://www.guardian.co.uk/sport/datablog/2012/aug/13/olympics-2012-cost-per-medal-team-gb-funding