def display_drilldown_as_ul(category, using='categories.Category'): """ Render the category with ancestors and children using the ``categories/ul_tree.html`` template. Example:: {% display_drilldown_as_ul "/Grandparent/Parent" %} or :: {% display_drilldown_as_ul category_obj %} Returns:: <ul> <li><a href="/categories/">Top</a> <ul> <li><a href="/categories/grandparent/">Grandparent</a> <ul> <li><a href="/categories/grandparent/parent/">Parent</a> <ul> <li><a href="/categories/grandparent/parent/child1">Child1</a></li> <li><a href="/categories/grandparent/parent/child2">Child2</a></li> <li><a href="/categories/grandparent/parent/child3">Child3</a></li> </ul> </li> </ul> </li> </ul> </li> </ul> """ cat = get_category(category, using) return {'category': cat, 'path': drilldown_tree_for_node(cat) or []}
def render(self, context): try: if self.category is not None: context[self.varname] = drilldown_tree_for_node(self.category) else: context[self.varname] = None except Category.DoesNotExist: context[self.varname] = None return ''
def render(self, context): try: category = self.category.resolve(context) except template.VariableDoesNotExist: category = self.category.var try: if category is not None: context[self.varname] = drilldown_tree_for_node(category) else: context[self.varname] = [] except Category.DoesNotExist: context[self.varname] = [] return ''
def render(self, context): """Render this node.""" category = resolve(self.category, context) if isinstance(category, CategoryBase): cat = category else: cat = get_category(category, self.model) try: context[self.varname] = drilldown_tree_for_node( cat) if cat is not None else [] except Exception: context[self.varname] = [] return ""
def render(self, context): category = resolve(self.category, context) if isinstance(category, CategoryBase): cat = category else: cat = get_category(category, self.model) try: if cat is not None: context[self.varname] = drilldown_tree_for_node(cat) else: context[self.varname] = [] except: context[self.varname] = [] return ''
def render(self, context): # Let any VariableDoesNotExist raised bubble up args = [self.node.resolve(context)] if self.foreign_key is not None: app_label, model_name, fk_attr = self.foreign_key.split('.') cls = get_model(app_label, model_name) if cls is None: raise template.TemplateSyntaxError(_('drilldown_tree_for_node tag was given an invalid model: %s') % '.'.join([app_label, model_name])) try: cls._meta.get_field(fk_attr) except FieldDoesNotExist: raise template.TemplateSyntaxError(_('drilldown_tree_for_node tag was given an invalid model field: %s') % fk_attr) args.extend([cls, fk_attr, self.count_attr, self.cumulative]) context[self.context_var] = drilldown_tree_for_node(*args) return ''
def display_drilldown_as_ul(category, using="categories.Category"): """ Render the category with ancestors and children using the ``categories/ul_tree.html`` template. Example: The template code of:: {% display_drilldown_as_ul "/Grandparent/Parent" %} or:: {% display_drilldown_as_ul category_obj %} might render as:: <ul> <li><a href="/categories/">Top</a> <ul> <li><a href="/categories/grandparent/">Grandparent</a> <ul> <li><a href="/categories/grandparent/parent/">Parent</a> <ul> <li><a href="/categories/grandparent/parent/child1">Child1</a></li> <li><a href="/categories/grandparent/parent/child2">Child2</a></li> <li><a href="/categories/grandparent/parent/child3">Child3</a></li> </ul> </li> </ul> </li> </ul> </li> </ul> Args: category: A variable reference to or the name of the category to display using: A variable reference to or the name of the category model to search for. Returns: The inclusion template """ cat = get_category(category, using) if cat is None: return {"category": cat, "path": []} else: return {"category": cat, "path": drilldown_tree_for_node(cat)}
def retrieve(self, request, pk=None): try: uuid.UUID(pk) except ValueError: raise Http404 dept = get_object_or_404(Department, uuid=pk) serializer = self.serializer_class(dept, context=self.get_serializer_context()) include_hierarchy = request.query_params.get('include_hierarchy') data = serializer.data if (include_hierarchy is not None and include_hierarchy.lower() not in ['no', 'false', '0']): hierarchy = drilldown_tree_for_node(dept) data['hierarchy'] = self.serializer_class( hierarchy, many=True, context=self.get_serializer_context()).data return Response(data)
def retrieve(self, request, pk=None): try: uuid.UUID(pk) except ValueError: raise Http404 dept = get_object_or_404(Department, uuid=pk) serializer = self.serializer_class( dept, context=self.get_serializer_context()) include_hierarchy = request.query_params.get('include_hierarchy') data = serializer.data if (include_hierarchy is not None and include_hierarchy.lower() not in ['no', 'false', '0']): hierarchy = drilldown_tree_for_node(dept) data['hierarchy'] = self.serializer_class( hierarchy, many=True, context=self.get_serializer_context()).data return Response(data)