@@ -109,12 +109,18 @@ def unfollow_all_courses(request):
109109 return redirect ("home" )
110110
111111
112+ @dataclass
113+ class ChildCategory :
114+ category : Category
115+ url : str
116+
117+
112118@dataclass
113119class Column :
114120 category : Category
115- children : list [Category ]
121+ children : list [ChildCategory ]
116122 depth : int
117- category_prefix : str
123+ url : str
118124
119125
120126def finder (request , slugs : str = "" ):
@@ -128,29 +134,32 @@ def finder(request, slugs: str = ""):
128134 raise Http404 (f"Invalid category path, { i } " )
129135
130136 columns = []
131- max_depth = len (categories )
132137 for i , category in enumerate (categories ):
133- depth = max_depth - i
134- path_list = ["." ] + [".." ] * (depth - 1 )
138+ slug_path = "/" .join (slug_list [: i + 1 ])
139+ children = category .children .order_by (
140+ Case (
141+ When (type = Category .CategoryType .BACHELOR , then = Value (0 )),
142+ When (type = Category .CategoryType .MASTER , then = Value (1 )),
143+ When (
144+ type = Category .CategoryType .MASTER_SPECIALIZATION ,
145+ then = Value (2 ),
146+ ),
147+ default = Value (3 ),
148+ ),
149+ "name" ,
150+ ).all ()
135151 columns .append (
136152 Column (
137153 category ,
138- list (
139- category .children .order_by (
140- Case (
141- When (type = Category .CategoryType .BACHELOR , then = Value (0 )),
142- When (type = Category .CategoryType .MASTER , then = Value (1 )),
143- When (
144- type = Category .CategoryType .MASTER_SPECIALIZATION ,
145- then = Value (2 ),
146- ),
147- default = Value (3 ),
148- ),
149- "name" ,
150- ).all ()
151- ),
152- depth ,
153- "/" .join (path_list ),
154+ [
155+ ChildCategory (
156+ child ,
157+ reverse ("catalog:finder" , args = [f"{ slug_path } /{ child .slug } " ]),
158+ )
159+ for child in children
160+ ],
161+ len (categories ) - i ,
162+ reverse ("catalog:finder" , args = [slug_path ]),
154163 )
155164 )
156165
0 commit comments