def show_block_cards(context): """ Возвращает список разделов + список товаров """ obj = context.get('object') items = get_sorted_content_objects( get_content_objects(obj.tree.get().get_children())) sections, products = [], [] for item in items: item_data = { 'title': item.title, 'get_absolute_url': item.get_absolute_url(), 'description': item.description, 'image': AttachmentImage.objects.filter( object_id=item.id, content_type=ContentType.objects.get_for_model(item)).first() } if item.leaf: products.append(item_data) else: sections.append(item_data) context['object_list'] = sections + products return context
def render_tag(self, context, instance, model_type, descendants, varname): if instance: if descendants == DESCENDANTS_TYPE_ALL: children = instance.tree.get().get_descendants() elif descendants == DESCENDANTS_TYPE_DIRECT: children = instance.tree.get().get_children() else: children = TreeItem.objects.root_nodes() if model_type: ModelClass = None for model_cls in get_catalog_models(): if model_cls._meta.model_name == model_type: ModelClass = model_cls if ModelClass is not None: allowed_ids = children.filter( content_type__model=model_type).values_list('object_id', flat=True) queryset = ModelClass.objects.filter(id__in=allowed_ids, show=True).order_by('tree__tree_id', 'tree__lft') else: queryset = [] else: queryset = get_content_objects(children) if varname: context[varname] = queryset return u'' else: context['children'] = queryset return render_to_string(self.template, context)
def render_tag(self, context, instance, model_type, descendants, varname): if instance: if descendants == DESCENDANTS_TYPE_ALL: children = instance.tree.get().get_descendants() elif descendants == DESCENDANTS_TYPE_DIRECT: children = instance.tree.get().get_children() else: children = TreeItem.objects.root_nodes() if model_type: ModelClass = None for model_cls in get_catalog_models(): if model_cls._meta.model_name == model_type: ModelClass = model_cls if ModelClass is not None: allowed_ids = children.filter( content_type__model=model_type).values_list('object_id', flat=True) queryset = ModelClass.objects.filter(id__in=allowed_ids, show=True).order_by( 'tree__tree_id', 'tree__lft') else: queryset = [] else: queryset = get_content_objects(children) if varname: context[varname] = queryset return u'' else: context['children'] = queryset return render_to_string(self.template, context)
def catalog_breadcrumbs(context, instance): """ Get breadcrumbs for catalog object """ treeitem = instance.tree.get() context.update({'breadcrumbs': get_content_objects(treeitem.get_ancestors())}) return context
def catalog_breadcrumbs(context, instance): """ Get breadcrumbs for catalog object """ treeitem = instance.tree.get() context.update( {'breadcrumbs': get_content_objects(treeitem.get_ancestors())}) return context
def show_block_sitemap(context): """ Отображение блока карты сайта """ data = [] for page in Page.objects.navigation().order_by("tree_id"): data.append({ 'title': page.title(), 'get_absolute_url': page.get_absolute_url(), 'children': get_page_children_data(page) }) catalog_root = Root.objects.all().first() if catalog_root: catalog_data = [] for child in get_sorted_content_objects( get_content_objects(catalog_root.tree.get().get_children())): if child.__class__.__name__ in settings.CATALOG_SITEMAP_HTML_MODELS: catalog_data.append({ 'title': child.title, 'get_absolute_url': child.get_absolute_url(), 'children': get_catalog_children(child.tree.get()) }) data.append({ 'title': catalog_root.title, 'get_absolute_url': catalog_root.get_absolute_url(), 'children': catalog_data }) news_root = NewsRoot.objects.all().first() if news_root: news_data = [] for new in CustomNews.objects.filter(show=True): news_data.append({ 'title': new.title, 'get_absolute_url': new.get_absolute_url(), 'children': [] }) data.append({ 'title': news_root.title, 'get_absolute_url': news_root.get_absolute_url(), 'children': news_data }) data.append({ 'title': u'Поиск по сайту', 'get_absolute_url': reverse('search'), 'children': [] }) context['object_list'] = data return context
def get_catalog_children(node): """ Возвращает данные о потомках элемента каталога """ data = [] for child in get_sorted_content_objects(get_content_objects(node.get_children())): if child.__class__.__name__ in settings.CATALOG_SITEMAP_HTML_MODELS: data.append({ 'title': child.title, 'get_absolute_url': child.get_absolute_url(), 'children': get_catalog_children(child.tree.get()) }) return data
def render_tag(self, context, treeitem, tree_type, template): if treeitem: tree_list = list(treeitem.get_children()) else: tree_list = list(TreeItem.objects.root_nodes()) context['tree_list'] = get_content_objects(tree_list) context['type'] = tree_type if template: output = render_to_string(template, context) else: output = render_to_string(self.template, context) return output
def render_tag(self, context, treeitem, tree_type, template): if treeitem: tree_list = list(treeitem.get_children()) else: tree_list = list(TreeItem.objects.root_nodes()) context['tree_list'] = get_content_objects(tree_list) context['type'] = tree_type if template: output = render_to_string(template, context) else: output = render_to_string(self.template, context) return output
def root_sections(self): """ Возвращает список разделов верхнего уровня""" return get_sorted_content_objects( get_content_objects(self.tree.get().get_children(), allowed_models=(Section, )))