<s> from django import template <EOL> from django . utils . translation import ugettext as _ <EOL> register = template . Library ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def bar ( quantity , start , end , bar_class = None , show_label = True ) : <EOL> """<STR_LIT>""" <EOL> assert quantity <= end , "<STR_LIT>" <EOL> try : <EOL> value = ( quantity - start ) * <NUM_LIT:100> / ( end - start ) <EOL> except ( TypeError , ZeroDivisionError ) : <EOL> return { '<STR_LIT>' : False } <EOL> VALUES = ( <EOL> ( <NUM_LIT:20> , '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> , '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> , '<STR_LIT:info>' , _ ( '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> , '<STR_LIT:info>' , _ ( '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> , '<STR_LIT:success>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> for boundary , css_class , label in VALUES : <EOL> if value < boundary : <EOL> break <EOL> if not bar_class : <EOL> bar_class = css_class <EOL> if not show_label : <EOL> label = '<STR_LIT>' <EOL> return { '<STR_LIT:width>' : value , '<STR_LIT>' : bar_class , '<STR_LIT:label>' : label , <EOL> '<STR_LIT>' : quantity , '<STR_LIT>' : True } </s>
