Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not request.site:
raise Http404
if request.resolver_match.url_name == 'entry_page_serve_slug':
# Splitting the request path and obtaining the path_components
# this way allows you to place the blog at the level you want on
# your sitemap.
# Example:
# splited_path = ['es', 'blog', '2016', '06', '23', 'blog-entry']
# slicing this way you obtain:
# path_components = ['es', 'blog', 'blog-entry']
# with the oldest solution you'll get ['es', 'blog-entry']
# and a 404 will be raised
splited_path = strip_prefix_and_ending_slash(request.path).split("/")
path_components = splited_path[:-4] + splited_path[-1:]
else:
path_components = [strip_prefix_and_ending_slash(request.path).split('/')[-1]]
page, args, kwargs = request.site.root_page.specific.route(request, path_components)
for fn in hooks.get_hooks('before_serve_page'):
result = fn(page, request, args, kwargs)
if isinstance(result, HttpResponse):
return result
return page.serve(request, *args, **kwargs)
def get_by_path(self, blog_path):
# Look for the blog checking all the path
from .models import BlogPage
blogs = BlogPage.objects.filter(slug=blog_path.split("/")[-1])
for blog in blogs:
if strip_prefix_and_ending_slash(blog.specific.last_url_part) == blog_path:
return blog.specific
return
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})
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
})