Skip to content

Commit

Permalink
Consolidate votes in a dict in db.review.get_by_id() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2611 authored and gentlecat committed Jul 20, 2017
1 parent 921b514 commit f7fe1a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions critiquebrainz/db/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ def get_by_id(review_id):
"full_name": review["full_name"],
}
votes = db_revision.votes(review["last_revision"]["id"])
review["votes_positive_count"] = votes["positive"]
review["votes_negative_count"] = votes["negative"]
review["popularity"] = review["votes_positive_count"] - review["votes_negative_count"]
review["votes"] = {
"positive": votes["positive"],
"negative": votes["negative"],
}
review["popularity"] = review["votes"]["positive"] - review["votes"]["negative"]
return review


Expand Down
4 changes: 2 additions & 2 deletions critiquebrainz/frontend/templates/review/entity/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ <h3>{{ review_credit(review, user_picture_size=24) }}</h3>
{% else %}
<em class="text-muted">{{ _('Published on %(date)s', date = review.created|date) }}</em><br />
<em class="text-muted">{{ _('Written in %(language)s', language = review.language|language_name) }}</em><br />
{% set votes_total = review.votes_positive_count + review.votes_negative_count %}
{% set votes_total = review.votes.positive + review.votes.negative %}
<em class="text-muted">
{% if votes_total > 0 %}
{{ _('%s out of %s people have found this review useful' % (review.votes_positive_count, votes_total)) }}
{{ _('%s out of %s people have found this review useful' % (review.votes.positive, votes_total)) }}
{% else %}
{{ _('This review has not yet been rated') }}
{% endif %}
Expand Down
12 changes: 8 additions & 4 deletions critiquebrainz/ws/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def review_entity_handler(review_id):
"karma": 0,
"user_type": "Noob"
},
"votes_negative": 0,
"votes_positive": 0
"votes": {
"positive": 0,
"negative": 0
}
}
}
Expand Down Expand Up @@ -294,8 +296,10 @@ def review_list_handler():
"karma": 0,
"user_type": "Noob"
},
"votes_negative": 0,
"votes_positive": 0
"votes": {
"positive": 0,
"negative": 0
}
}
]
}
Expand Down

0 comments on commit f7fe1a3

Please sign in to comment.