Skip to content

Commit

Permalink
factorize the sitemap code for content types
Browse files Browse the repository at this point in the history
  • Loading branch information
gasche committed Nov 21, 2016
1 parent 2de8a67 commit f6f9106
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions zds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,27 @@


# SiteMap data
class TutoSitemap(Sitemap):
class ContentSitemap(Sitemap):
changefreq = 'weekly'
priority = 1

def items(self):
return PublishedContent.objects.filter(must_redirect=False, content_type="TUTORIAL").prefetch_related('content')
return PublishedContent.objects.filter(must_redirect=False, content_type=self.content_type).prefetch_related('content')

def lastmod(self, tuto):
return tuto.update_date or tuto.publication_date
def lastmod(self, content):
return content.update_date or content.publication_date

def location(self, tuto):
return tuto.get_absolute_url_online()
def location(self, content):
return content.get_absolute_url_online()

class TutoSitemap(ContentSitemap):
content_type = "TUTORIAL"

class ArticleSitemap(Sitemap):
changefreq = 'weekly'
priority = 1

def items(self):
return PublishedContent.objects.filter(must_redirect=False, content_type="ARTICLE").prefetch_related('content')

def lastmod(self, article):
return article.update_date or article.publication_date

def location(self, article):
return article.get_absolute_url_online()

class OpinionSitemap(Sitemap):
changefreq = 'weekly'
priority = 1

def items(self):
return PublishedContent.objects.filter(must_redirect=False, content_type="OPINION").prefetch_related('content')

def lastmod(self, opinion):
return opinion.update_date or opinion.publication_date

def location(self, opinion):
return opinion.get_absolute_url_online()
class ArticleSitemap(ContentSitemap):
content_type = "ARTICLE"

class OpinionSitemap(ContentSitemap):
content_type = "OPINION"

class PageSitemap(Sitemap):
changefreq = 'weekly'
Expand Down

0 comments on commit f6f9106

Please sign in to comment.