def except_collection(self, collection_name): try: collection = Collection.query().get(name=collection_name) items = collection["items"] except Collection.DoesNotExist: items = [] return self.filter(pk__notin=items)
def except_collection(self, collection_name): try: collection = Collection.query().get(name=collection_name) items = collection['items'] except Collection.DoesNotExist: items = [] return self.filter(pk__notin=items)
def list(request, template='page_list', **kwargs): site = getattr(request, 'site', None) pages = Page.query() if site: pages = site['pages'] collections = Collection.query() if 'slug2' in kwargs: items = [] for item in Collection.query().filter(site=site, slug=kwargs['slug2']): items.extend(item['items']) collections = collections.filter(pk__in=items) if 'slug1' in kwargs: collection = get_object_or_404(collections, slug=kwargs['slug1']) pages = pages.filter(pk__in=collection['items']) return render_to_response(request, template, {'pages':pages})
def category_view(request, slug, template="page_view", **kwargs): collections = Collection.query().filter(site=request.site) pages = Page.query().published() breadcrumbs = [] if 'slug1' in kwargs: items = [] category = None for item in collections.filter(slug=kwargs['slug1']): category = item items.extend(item['items']) if category: breadcrumbs.append((category['title'] or category['name'], category.get_url())) pages = pages.filter(site=request.site, pk__in=items) page = get_object_or_404(pages, slug=slug) request.breadcrumbs(breadcrumbs) return _render_page(request, page, template)
def view(request, slug, template="page_view", **kwargs): try: if slug == Page.query().published().filter(is_home=True).get().get_url(): return redirect_to(request, '/') except: pass if not getattr(request, 'site', None): raise Http404 page = _get_page_by_slug(request, slug) # don't show page if it belongs to collection with a slug collections = Collection.query().filter(site=request.site, slug__notequal='', items__contains=page['pk']) if collections.count(): raise Http404 return _render_page(request, page, template)
def get_url(self): kwargs = {} collections = Collection.query().filter(site=self['site'], items__contains=str(self['pk'])) if collections.count(): kwargs = collections[0].get_slugs() # TODO: what to do if page belongs to more than 1 collection? kwargs['slug'] = self['slug'] try: from routes import dynamic_url_patterns url_patterns = dynamic_url_patterns[self['site']['name']] if self['site']['name'] in dynamic_url_patterns else [] except ImportError: url_patterns = [] try: return reverse('pages_views_category_view', kwargs=kwargs, dynamic_url_patterns=url_patterns) except: return '/%s/' % self['slug']
def get_url(self): kwargs = {} collections = Collection.query().filter(site=self['site'], items__contains=str( self['pk'])) if collections.count(): kwargs = collections[0].get_slugs( ) # TODO: what to do if page belongs to more than 1 collection? kwargs['slug'] = self['slug'] try: from routes import dynamic_url_patterns url_patterns = dynamic_url_patterns[self['site']['name']] if self[ 'site']['name'] in dynamic_url_patterns else [] except ImportError: url_patterns = [] try: return reverse('pages_views_category_view', kwargs=kwargs, dynamic_url_patterns=url_patterns) except: return '/%s/' % self['slug']