def get_nav_child_pages(self, page, nav_name=None): """ Return a list of navigation items for all child pages of the given page, if this feature is enabled via CMS_NAVIGATION_INCLUDE_CHILD_PAGES. """ # empty list if feature is not enabled if not settings.CMS_NAVIGATION_INCLUDE_CHILD_PAGES: return [] # empty list if the given page is not a page that has child pages if not isinstance(page, get_page_model()): return [] # valid child page model that is not excluded for navigation child_page_model = page.get_entity_model() if not child_page_model or self.child_page_model_excluded_from_nav(child_page_model): return [] # get cached list of child pages for the given page key = unicode(page.pk) if key not in self.child_page_cache: self.child_page_cache[key] = [] # get child pages for this page child_pages = child_page_model.filter_visibility( child_page_model.objects.filter(page=page).exclude(disabled=True).order_by('seq') ) self.child_page_cache[key] = list([self.get_nav_item(p, nav_name) for p in child_pages]) # receive list of child pages return self.child_page_cache.get(key, [])
def get_pages(self): """ Return a list of navigate-able content pages """ page_model = get_page_model() related_fields = [] if hasattr(settings, 'CMS_NAVIGATION_RELATED_FIELDS'): related_fields = related_fields + settings.CMS_NAVIGATION_RELATED_FIELDS related_fields = filter( lambda field: hasattr(page_model, field), related_fields ) pages = list( page_model.filter_visibility( self.get_objects( page_model.objects.select_related(*related_fields).filter( Q(_nav__isnull=False) | # appears in at least one # navigation section Q(identifier__isnull=False), # OR has an identifier disabled=False # not disabled ).order_by( 'seq', 'title' ) ) ) ) return pages
def clean(self): d = self.cleaned_data slug = d.get('slug') page = d.get('page') if slug and page: # no collision with any other child page (with the same parent page) pages = self._meta.model.objects.filter(page=page, slug=slug) if self._edit and not self.is_duplicate: pages = pages.exclude(pk=self._instance.id) if pages.count() > 0: self.field_error('slug', PageForm.ERROR_SLUG_COLLISION) # parent is the homepage! if page.is_homepage: # collision with any other page, if the parent page is the homepage if get_page_model().objects.filter(is_homepage=False, slug=slug).count() > 0: self.field_error('slug', PageForm.ERROR_SLUG_COLLISION) # is the slug reserved for system purposes? if collides_with_reserved_name(slug): self.field_error('slug', PageForm.ERROR_SLUG_SYSTEM_NAME) return d
class Meta: model = get_page_model() fields = '__all__' widgets = { 'identifier': BootstrapTextInput(prepend='#', attrs={ 'class': 'make-identifier', 'autocomplete': 'off' }), } tabs = [{ 'title': 'Navigation', 'fields': [ 'nav', 'navigation_title', 'identifier', 'parent', ] }, { 'title': 'Presentation', 'fields': [ 'entity_type', ] }] sections = {'nav': 'Navigation', 'parent': 'Hierarchy'}
def configure(self, request, instance=None, edit=True): super(ChildPageForm, self).configure(request, instance, edit) # configure parent page dropdown with list of pages that are available # for the given child page model. pages = get_page_model().objects.filter( entity_type=self._meta.model.__name__) self.fields['page'].queryset = pages # do not show empty label self.fields['page'].empty_label = None
def links(self, request): """ Return a list of links (e.g. pages, documents etc). """ items = [] if 'cubane.cms' in settings.INSTALLED_APPS: from cubane.cms import get_page_model from cubane.cms.views import get_cms # pages page_model = get_page_model() pages = page_model.objects.filter(disabled=False) pages = Acl.of(page_model).filter(request, pages) items.append({ 'title': page_model._meta.verbose_name_plural.title(), 'type': page_model.__name__, 'slug': slugify(page_model._meta.verbose_name_plural), 'links': [{ 'id': x.id, 'title': x.title } for x in pages] }) # child pages cms = get_cms() for model in cms.get_child_page_models(): child_pages = model.objects.filter(disabled=False) child_pages = Acl.of(model).filter(request, child_pages) items.append({ 'title': model._meta.verbose_name_plural.title(), 'type': model.__name__, 'slug': slugify(model._meta.verbose_name_plural), 'links': [{ 'id': x.id, 'title': x.title } for x in child_pages] }) # call back into CMS class to receive more links link_builder = LinkBuilder(request) cms.on_object_links(link_builder) items.extend(link_builder.links) if 'cubane.media' in settings.INSTALLED_APPS: from cubane.media.models import Media media = Media.objects.filter(is_image=False) media = Acl.of(Media).filter(request, media) items.append({ 'title': 'Documents', 'type': 'Media', 'slug': 'documents', 'links': [{ 'id': x.id, 'title': x.caption } for x in media] }) return {'items': items, 'links': None}
def is_colliding_page(self, *args, **kwargs): pages = get_page_model().objects.filter(**kwargs) if self._edit: pages = pages.exclude(pk=self._instance.id) return pages.count() > 0
def __init__(self, *args, **kwargs): kwargs['queryset'] = get_page_model().objects.all() kwargs['name'] = 'Pages' kwargs['browse'] = reverse_lazy('cubane.cms.pages.index') kwargs['create'] = reverse_lazy('cubane.cms.pages.create') super(BrowsePagesField, self).__init__(*args, **kwargs)
def get_supported_models(self): return [ get_page_model(), ChildPage, Entity ]