<s> from django import template <EOL> from django . template import RequestContext <EOL> from django . template . loader import render_to_string <EOL> from lfs . catalog . models import Category <EOL> from lfs . manufacturer . models import Manufacturer <EOL> register = template . Library ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def category_filter ( context , css_class = "<STR_LIT>" , name = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> selected = request . session . get ( "<STR_LIT>" , { } ) . get ( "<STR_LIT>" ) <EOL> categories = [ ] <EOL> for category in Category . objects . filter ( parent = None ) : <EOL> children = category_filter_children ( request , category , name ) <EOL> categories . append ( { <EOL> "<STR_LIT:id>" : category . id , <EOL> "<STR_LIT:name>" : category . name , <EOL> "<STR_LIT>" : children , <EOL> "<STR_LIT>" : str ( category . id ) == selected , <EOL> } ) <EOL> result = { "<STR_LIT>" : categories , "<STR_LIT>" : css_class , "<STR_LIT:name>" : name , "<STR_LIT>" : selected } <EOL> return result <EOL> def category_filter_children ( request , category , name = "<STR_LIT>" , level = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> categories = [ ] <EOL> for category in category . category_set . all ( ) : <EOL> children = category_filter_children ( request , category , name , level + <NUM_LIT:1> ) <EOL> categories . append ( { <EOL> "<STR_LIT:id>" : category . id , <EOL> "<STR_LIT:name>" : "<STR_LIT>" % ( "<STR_LIT>" * level * <NUM_LIT:5> , category . name ) , <EOL> "<STR_LIT>" : children , <EOL> "<STR_LIT>" : level , <EOL> "<STR_LIT>" : str ( category . id ) == request . session . get ( "<STR_LIT>" , { } ) . get ( "<STR_LIT>" ) <EOL> } ) <EOL> result = render_to_string ( "<STR_LIT>" , RequestContext ( request , { <EOL> "<STR_LIT>" : categories <EOL> } ) ) <EOL> return result <EOL> @ register . inclusion_tag ( '<STR_LIT>' , takes_context = True ) <EOL> def manufacturer_filter ( context , css_class = "<STR_LIT>" , name = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( "<STR_LIT>" ) <EOL> selected = request . session . get ( "<STR_LIT>" , { } ) . get ( "<STR_LIT>" ) <EOL> manufacturers = [ ] <EOL> for manufacturer in Manufacturer . objects . all ( ) : <EOL> manufacturers . append ( { <EOL> "<STR_LIT:id>" : manufacturer . id , <EOL> "<STR_LIT:name>" : manufacturer . name , <EOL> "<STR_LIT>" : str ( manufacturer . id ) == selected , <EOL> } ) <EOL> result = { "<STR_LIT>" : manufacturers , "<STR_LIT>" : css_class , "<STR_LIT:name>" : name , "<STR_LIT>" : selected } <EOL> return result </s>
