Ticket #3184: defaultfilters.3.diff
File defaultfilters.3.diff, 1.6 KB (added by , 18 years ago) |
---|
-
django/template/defaultfilters.py
5 5 from django.utils.translation import gettext 6 6 import re 7 7 import random as random_module 8 from types import StringTypes, ListType 8 9 9 10 register = Library() 10 11 … … 287 288 </ul> 288 289 </li> 289 290 """ 290 def _ helper(value, tabs):291 def _create(value, tabs): 291 292 indent = '\t' * tabs 292 293 if value[1]: 293 294 return '%s<li>%s\n%s<ul>\n%s\n%s</ul>\n%s</li>' % (indent, value[0], indent, 294 295 '\n'.join([_helper(v, tabs+1) for v in value[1]]), indent, indent) 295 296 else: 296 297 return '%s<li>%s</li>' % (indent, value[0]) 298 299 def _helper(value, tabs): 300 if type(value) != ListType: 301 value = [value] 302 l = len(value) 303 if l == 0: 304 return '' 305 else: 306 html = [] 307 i = 0 308 while i < l: 309 if type(value[i]) == ListType: 310 html.append(_create(['', value[i]], tabs)) 311 i += 1 312 continue 313 elif i < l-1 and type(value[i+1]) == ListType: 314 html.append(_create([value[i], value[i+1]], tabs)) 315 i += 2 316 continue 317 else: 318 html.append(_create([value[i], []], tabs)) 319 i += 1 320 return '\n'.join(html) 321 297 322 return _helper(value, 1) 298 323 299 324 ###################