/
urls.py
84 lines (75 loc) · 3.07 KB
/
urls.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from django.conf import settings
from django.urls import reverse, path, include
from .feeds import BlogPageFeed
from .views import EntryPageServe, EntryPageUpdateCommentsView
from .utils import strip_prefix_and_ending_slash
urlpatterns = [
path(
route="entry_page/<entry_page_id>/update_comments/",
view=EntryPageUpdateCommentsView.as_view(),
name="entry_page_update_comments",
),
path(
route="<path:blog_path>/<int:year>/<int:month>/<int:day>/<str:slug>/",
view=EntryPageServe.as_view(),
name="entry_page_serve_slug",
),
path(route="<int:year>/<int:month>/<int:day>/<str:slug>/", view=EntryPageServe.as_view(), name="entry_page_serve"),
path(route="<path:blog_path>/feed/", view=BlogPageFeed(), name="blog_page_feed_slug"),
path(route="feed/", view=BlogPageFeed(), name="blog_page_feed"),
]
if not getattr(settings, "PUPUT_AS_PLUGIN", False):
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.contrib.sitemaps.views import sitemap
urlpatterns.extend(
[
path(route="blog_admin/", view=include(wagtailadmin_urls)),
path(route="", view=include(wagtail_urls)),
path(route="documents/", view=include(wagtaildocs_urls)),
path(route="sitemap.xml", view=sitemap),
]
)
def get_entry_url(entry, blog_page, root_page):
"""
Get the entry url given and entry page a blog page instances.
It will use an url or another depending if blog_page is the root page.
"""
if root_page == blog_page:
return reverse(
"entry_page_serve",
kwargs={
"year": entry.date.strftime("%Y"),
"month": entry.date.strftime("%m"),
"day": entry.date.strftime("%d"),
"slug": entry.slug,
},
)
else:
# The method get_url_parts provides a tuple with a custom URL routing
# scheme. In the last position it finds the subdomain of the blog, which
# it is used to construct the entry url.
# Using the stripped subdomain it allows Puput to generate the urls for
# every sitemap level
blog_path = strip_prefix_and_ending_slash(blog_page.specific.last_url_part)
return reverse(
"entry_page_serve_slug",
kwargs={
"blog_path": blog_path,
"year": entry.date.strftime("%Y"),
"month": entry.date.strftime("%m"),
"day": entry.date.strftime("%d"),
"slug": entry.slug,
},
)
def get_feeds_url(blog_page, root_page):
"""
Get the feeds urls a blog page instance.
It will use an url or another depending if blog_page is the root page.
"""
if root_page == blog_page:
return reverse("blog_page_feed")
else:
blog_path = strip_prefix_and_ending_slash(blog_page.specific.last_url_part)
return reverse("blog_page_feed_slug", kwargs={"blog_path": blog_path})