Merge pull request #13 from lca2017/chrisjrn/002-abstain

Adds abstensions to the vote model
This commit is contained in:
Scott Bragg 2016-06-18 14:38:35 +10:00 committed by GitHub
commit a22b4bc2f8
2 changed files with 13 additions and 0 deletions

View file

@ -19,10 +19,13 @@ def score_expression():
return ( return (
(2 * F("plus_two") + F("plus_one")) - (2 * F("plus_two") + F("plus_one")) -
(F("minus_one") + 2 * F("minus_two")) (F("minus_one") + 2 * F("minus_two"))
) / (
F("vote_count") - F("abstain") * 1.0
) )
class Votes(object): class Votes(object):
ABSTAIN = "0"
PLUS_TWO = "+2" PLUS_TWO = "+2"
PLUS_ONE = "+1" PLUS_ONE = "+1"
MINUS_ONE = "1" MINUS_ONE = "1"
@ -33,6 +36,7 @@ class Votes(object):
(PLUS_ONE, _("+1 — OK proposal, but I will not argue for it to be accepted.")), (PLUS_ONE, _("+1 — OK proposal, but I will not argue for it to be accepted.")),
(MINUS_ONE, _("1 — Weak proposal, but I will not argue strongly against acceptance.")), (MINUS_ONE, _("1 — Weak proposal, but I will not argue strongly against acceptance.")),
(MINUS_TWO, _("2 — Serious issues and I will argue to reject this proposal.")), (MINUS_TWO, _("2 — Serious issues and I will argue to reject this proposal.")),
(ABSTAIN, _("Abstain - I do not want to review this proposal and I do not want to see it again.")),
] ]
VOTES = Votes() VOTES = Votes()
@ -177,6 +181,7 @@ class Review(models.Model):
def css_class(self): def css_class(self):
return { return {
self.VOTES.ABSTAIN: "abstain",
self.VOTES.PLUS_TWO: "plus-two", self.VOTES.PLUS_TWO: "plus-two",
self.VOTES.PLUS_ONE: "plus-one", self.VOTES.PLUS_ONE: "plus-one",
self.VOTES.MINUS_ONE: "minus-one", self.VOTES.MINUS_ONE: "minus-one",
@ -210,6 +215,7 @@ class LatestVote(models.Model):
def css_class(self): def css_class(self):
return { return {
self.VOTES.ABSTAIN: "abstain",
self.VOTES.PLUS_TWO: "plus-two", self.VOTES.PLUS_TWO: "plus-two",
self.VOTES.PLUS_ONE: "plus-one", self.VOTES.PLUS_ONE: "plus-one",
self.VOTES.MINUS_ONE: "minus-one", self.VOTES.MINUS_ONE: "minus-one",
@ -222,6 +228,7 @@ class ProposalResult(models.Model):
score = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("0.00"), verbose_name=_("Score")) score = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("0.00"), verbose_name=_("Score"))
comment_count = models.PositiveIntegerField(default=0, verbose_name=_("Comment count")) comment_count = models.PositiveIntegerField(default=0, verbose_name=_("Comment count"))
vote_count = models.PositiveIntegerField(default=0, verbose_name=_("Vote count")) vote_count = models.PositiveIntegerField(default=0, verbose_name=_("Vote count"))
abstain = models.PositiveIntegerField(default=0, verbose_name=_("Abstain"))
plus_two = models.PositiveIntegerField(default=0, verbose_name=_("Plus two")) plus_two = models.PositiveIntegerField(default=0, verbose_name=_("Plus two"))
plus_one = models.PositiveIntegerField(default=0, verbose_name=_("Plus one")) plus_one = models.PositiveIntegerField(default=0, verbose_name=_("Plus one"))
minus_one = models.PositiveIntegerField(default=0, verbose_name=_("Minus one")) minus_one = models.PositiveIntegerField(default=0, verbose_name=_("Minus one"))
@ -244,6 +251,10 @@ class ProposalResult(models.Model):
result, created = cls._default_manager.get_or_create(proposal=proposal) result, created = cls._default_manager.get_or_create(proposal=proposal)
result.comment_count = Review.objects.filter(proposal=proposal).count() result.comment_count = Review.objects.filter(proposal=proposal).count()
result.vote_count = LatestVote.objects.filter(proposal=proposal).count() result.vote_count = LatestVote.objects.filter(proposal=proposal).count()
result.abstain = LatestVote.objects.filter(
proposal=proposal,
vote=VOTES.ABSTAIN,
).count()
result.plus_two = LatestVote.objects.filter( result.plus_two = LatestVote.objects.filter(
proposal=proposal, proposal=proposal,
vote=VOTES.PLUS_TWO vote=VOTES.PLUS_TWO
@ -265,6 +276,7 @@ class ProposalResult(models.Model):
def update_vote(self, vote, previous=None, removal=False): def update_vote(self, vote, previous=None, removal=False):
mapping = { mapping = {
VOTES.ABSTAIN: "abstain",
VOTES.PLUS_TWO: "plus_two", VOTES.PLUS_TWO: "plus_two",
VOTES.PLUS_ONE: "plus_one", VOTES.PLUS_ONE: "plus_one",
VOTES.MINUS_ONE: "minus_one", VOTES.MINUS_ONE: "minus_one",

View file

@ -40,6 +40,7 @@ def proposals_generator(request, queryset, user_pk=None, check_speaker=True):
ProposalResult.objects.get_or_create(proposal=obj) ProposalResult.objects.get_or_create(proposal=obj)
obj.comment_count = obj.result.comment_count obj.comment_count = obj.result.comment_count
obj.score = obj.result.score
obj.total_votes = obj.result.vote_count obj.total_votes = obj.result.vote_count
obj.plus_two = obj.result.plus_two obj.plus_two = obj.result.plus_two
obj.plus_one = obj.result.plus_one obj.plus_one = obj.result.plus_one