Add get_site and get_url_parts to the Page model reference docs

pull/2027/merge
Matt Westcott 2016-01-21 17:09:35 +00:00 zatwierdzone przez Karl Hobley
rodzic 4dff225d83
commit 7861c2b492
2 zmienionych plików z 15 dodań i 2 usunięć

Wyświetl plik

@ -95,6 +95,12 @@ In addition to the model fields provided, ``Page`` has many properties and metho
.. autoattribute:: full_url
.. automethod:: relative_url
.. automethod:: get_site
.. automethod:: get_url_parts
.. automethod:: route
.. automethod:: serve

Wyświetl plik

@ -749,10 +749,13 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
def get_url_parts(self):
"""
Determine the URL for this page and return it as a tuple of
(site_id, site_root_url, page_url_relative_to_site_root).
``(site_id, site_root_url, page_url_relative_to_site_root)``.
Return None if the page is not routable.
Pages with custom URL routing should override this.
This is used internally by the ``full_url``, ``url``, ``relative_url``
and ``get_site`` properties and methods; pages with custom URL routing
should override this method in order to have those operations return
the custom URLs.
"""
for (site_id, root_path, root_url) in Site.get_site_root_paths():
if self.url_path.startswith(root_path):
@ -816,6 +819,10 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
return root_url + page_path
def get_site(self):
"""
Return the Site object that this page belongs to.
"""
url_parts = self.get_url_parts()
if url_parts is None: