Merge pull request #839 from Benbb96/fix-kb-item-score

Fix KnowledgeBase item score to display as float
This commit is contained in:
Garret Wassermann 2020-06-29 20:08:45 -04:00 committed by GitHub
commit 8541e03b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -1031,8 +1031,9 @@ class KBItem(models.Model):
return super(KBItem, self).save(*args, **kwargs) return super(KBItem, self).save(*args, **kwargs)
def _score(self): def _score(self):
""" Return a score out of 10 or Unrated if no votes """
if self.votes > 0: if self.votes > 0:
return int(self.recommendations / self.votes) return (self.recommendations / self.votes) * 10
else: else:
return _('Unrated') return _('Unrated')
score = property(_score) score = property(_score)

View File

@ -29,7 +29,7 @@
<ul> <ul>
<li>{% blocktrans with item.recommendations as recommendations %}Recommendations: {{ recommendations }}{% endblocktrans %}</li> <li>{% blocktrans with item.recommendations as recommendations %}Recommendations: {{ recommendations }}{% endblocktrans %}</li>
<li>{% blocktrans with item.votes as votes %}Votes: {{ votes }}{% endblocktrans %}</li> <li>{% blocktrans with item.votes as votes %}Votes: {{ votes }}{% endblocktrans %}</li>
<li>{% blocktrans with item.score as score %}Overall Rating: {{ score }}{% endblocktrans %}</li> <li>{% blocktrans with item.score|floatformat as score %}Overall Rating: {{ score }}{% endblocktrans %}/10</li>
</ul> </ul>
</div> </div>
</div> </div>