-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitemaps.py
41 lines (28 loc) · 886 Bytes
/
sitemaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from datetime import datetime
from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from django.utils import timezone
from blog.models import Post
class SiteSitemap(Sitemap):
changefreq = "monthly"
priority = 0.5
def __init__(self, names):
self.names = names
def items(self):
return self.names
@staticmethod
def lastmod(obj):
return timezone.now()
def location(self, obj):
return reverse(obj)
class PostSitemap(Sitemap):
changefreq = "monthly"
priority = 1.0
def items(self):
right_now = datetime.now()
return Post.objects.filter(go_live_date__lte=right_now).exclude(take_down_date__lte=right_now)
@staticmethod
def lastmod(obj):
return obj.date_modified
def location(self, obj):
return reverse("blog:post", kwargs={"slug": obj.slug})