def root(request): ''' Render catalog root page. Templates: ``<app_label>/catalog_root.html`` ``catalog/catalog_root.html`` Parameter ``app_label`` looked up in ``CATALOG_MDOELS`` setting in settings.py Context taken from ``object_detail`` method from ``django.views.generic.list_detail``: object_list: list of objects is_paginated: are the results paginated? results_per_page: number of objects per page (if paginated) has_next: is there a next page? has_previous: is there a prev page? page: the current page next: the next page previous: the previous page pages: number of pages, total hits: number of objects, total last_on_page: the result number of the last of object in the object_list (1-indexed) first_on_page: the result number of the first object in the object_list (1-indexed) page_range: A list of the page numbers (1-indexed). ''' templates_list = ['%s/catalog_root.html' % app_name for app_name in get_data_appnames()] templates_list.append('catalog/root.html') t = loader.select_template(templates_list) extra_context = { 'template_name': t.name, } return object_list(request, TreeItem.objects.published().filter(parent=None), **extra_context)
def render_tag(self, context, instance, children_type, varname): # if instance is not None: if instance == 'root': treeitem = None elif instance == 'guess': # try to guess treeitem = get_treeitem_from_context(context) elif instance is None: treeitem = None else: if isinstance(instance, TreeItem): treeitem = instance else: try: treeitem = instance.tree.get() except AttributeError: raise TemplateSyntaxError('Instance argument must have `tree` attribute') if children_type: ModelClass = None for model_cls in connected_models(): if model_cls._meta.module_name == children_type: ModelClass = model_cls if ModelClass is not None: model_filter = get_q_filters()[ModelClass] if model_filter is not None: queryset = ModelClass.objects.filter(model_filter) else: queryset = ModelClass.objects.all() allowed_ids = TreeItem.objects.published().filter(parent=treeitem, content_type__model=children_type).values_list('object_id', flat=True) queryset = queryset.filter(id__in=allowed_ids) else: # Empty queryset = [] else: queryset = TreeItem.objects.published().filter(parent=treeitem) if varname: context[varname] = queryset return u'' else: self.templates[0:0] = ['%s/children_tag.html' % app_name for app_name in get_data_appnames()] context['children_queryset'] = children_qs return render_to_string(self.templates, context)