Add PageManager which returns PageQuerySet objects

pull/185/head
Karl Hobley 2014-04-07 16:51:14 +01:00
rodzic 0cbe15b741
commit fe9ce7503e
1 zmienionych plików z 55 dodań i 1 usunięć

Wyświetl plik

@ -129,6 +129,59 @@ def get_navigable_page_content_type_ids():
return _NAVIGABLE_PAGE_CONTENT_TYPE_IDS
class PageManager(models.Manager):
def get_query_set(self):
return PageQuerySet(self.model).order_by('path')
def live(self):
return self.get_query_set().live()
def not_live(self):
return self.get_query_set().not_live()
def page(self, other):
return self.get_query_set().page(other)
def not_page(self, other):
return self.get_query_set().not_page(other)
def descendant_of(self, other, inclusive=False):
return self.get_query_set().descendant_of(other, inclusive)
def not_descendant_of(self, other, inclusive=False):
return self.get_query_set().not_descendant_of(other, inclusive)
def child_of(self, other):
return self.get_query_set().child_of(other)
def not_child_of(self, other):
return self.get_query_set().not_child_of(other)
def ancestor_of(self, other, inclusive=False):
return self.get_query_set().ancestor_of(other, inclusive)
def not_ancestor_of(self, other, inclusive=False):
return self.get_query_set().not_ancestor_of(other, inclusive)
def parent_of(self, other):
return self.get_query_set().parent_of(other)
def not_parent_of(self, other):
return self.get_query_set().not_parent_of(other)
def sibling_of(self, other, inclusive=False):
return self.get_query_set().sibling_of(other, inclusive)
def not_sibling_of(self, other, inclusive=False):
return self.get_query_set().not_sibling_of(other, inclusive)
def type(self, model):
return self.get_query_set().type(model)
def not_type(self, model):
return self.get_query_set().not_type(model)
class PageBase(models.base.ModelBase):
"""Metaclass for Page"""
def __init__(cls, name, bases, dct):
@ -139,7 +192,8 @@ class PageBase(models.base.ModelBase):
# don't proceed with all this page type registration stuff
return
cls.query = PageQuerySet(model=cls)
# Add page manager
PageManager().contribute_to_class(cls, 'objects')
if 'template' not in dct:
# Define a default template path derived from the app name and model name