Skip to content

Commit

Permalink
add opinions to the sitemap (#3997)
Browse files Browse the repository at this point in the history
* add opinions to the sitemap

* factorize the sitemap code for content types
  • Loading branch information
gasche authored and artragis committed Apr 1, 2017
1 parent 28d57ad commit e6480c6
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions zds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@


# 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 ArticleSitemap(Sitemap):
changefreq = 'weekly'
priority = 1
class TutoSitemap(ContentSitemap):
content_type = "TUTORIAL"

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
class ArticleSitemap(ContentSitemap):
content_type = "ARTICLE"


def location(self, article):
return article.get_absolute_url_online()
class OpinionSitemap(ContentSitemap):
content_type = "OPINION"


class PageSitemap(Sitemap):
Expand All @@ -58,6 +60,7 @@ def location(self, item):
sitemaps = {
'tutos': TutoSitemap,
'articles': ArticleSitemap,
'opinions': OpinionSitemap,
'categories': GenericSitemap(
{'queryset': Category.objects.all()},
changefreq='yearly',
Expand Down

0 comments on commit e6480c6

Please sign in to comment.