Commits

Anonymous committed 245dead

чиним темплейттэг ranks_and_votes для случая с нулем голосов

Comments (0)

Files changed (1)

brainstill/templatetags/brainstill.py

     if num_votes == 0:
         promotes = demotes = dontcares = score = graph_length = 0
     else:
-        promotes = idea.promotes
-        demotes = idea.demotes
-        dontcares = idea.dontcares
         score = idea.score
         graph_length_func = getattr(settings, 'BRAINSTILL_GRAPH_LENGTH_FUNC',
                                     DEFAULT_GRAPH_LENGTH_FUNC)
         graph_length = graph_length_func(num_votes)
+        promotes = int(round(graph_length * idea.promotes / num_votes))
+        demotes = -int(round(graph_length * idea.demotes / num_votes))
+        dontcares = int(round(graph_length * idea.dontcares / num_votes))
     return {
         'idea': idea,
         'vote_choices': _VOTE_CHOICES,
         'num_votes': num_votes,
-        'promotes_length': int(round(graph_length * promotes / num_votes)),
-        'demotes_length': abs(int(round(graph_length * demotes / num_votes))),
-        'dontcares_length': int(round(graph_length * dontcares / num_votes)),
+        'promotes_length': promotes,
+        'demotes_length': demotes,
+        'dontcares_length': dontcares,
         'score': '+%d' % score if score > 0 else str(score)
     }