~linuxgoose/bocpress

ref: 40924823532a11a80361899796887dbbd22b6dbf bocpress/main/sitemaps.py -rw-r--r-- 1.3 KiB
40924823Jordan Robinson update allow user to see landing page when logged in 2 months ago
                                                                                
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from django.utils import timezone

from main import models


class StaticSitemap(Sitemap):
    priority = 1.0
    changefreq = "always"

    def items(self):
        return ["index"]

    def location(self, obj):
        return reverse(obj)


class PostSitemap(Sitemap):
    priority = 1.0
    changefreq = "daily"

    def __init__(self, subdomain):
        self.subdomain = subdomain

    def items(self):
        return models.Post.objects.filter(
            owner__username=self.subdomain,
            published_at__isnull=False,
            published_at__lte=timezone.now().date(),
        ).order_by("-published_at")

    def location(self, obj):
        return reverse("post_detail", kwargs={"slug": obj.slug})

    def lastmod(self, obj):
        return obj.updated_at


class PageSitemap(Sitemap):
    priority = 0.8
    changefreq = "daily"

    def __init__(self, subdomain):
        self.subdomain = subdomain

    def items(self):
        return models.Page.objects.filter(
            owner__username=self.subdomain, is_hidden=False
        )

    def location(self, obj):
        return reverse("page_detail", kwargs={"slug": obj.slug})

    def lastmod(self, obj):
        return obj.updated_at