Merge branch 'two-small-fixes' into 'master'

Two small fixes

See merge request !20
This commit is contained in:
Sachi King 2017-08-08 06:51:11 +00:00
commit 5a97c93861
2 changed files with 13 additions and 22 deletions

View file

@ -4,7 +4,7 @@ symposion_app
At this time, considerations have not been made to have the django project run
without additional infrastructure.
This can be configured in the future by switching the defualt
This can be configured in the future by switching the default
DEFAULT_FILE_STORAGE django default, and properly configuring django to load
subsequent configuration to switch this back to GCS on run in our testing
and production environments.
@ -28,12 +28,12 @@ GCS
SAML2
~~~~~
Please familurise yourself with Shibboleth configuraiton and the general
Please familiarise yourself with Shibboleth configuration and the general
flow of how to register a SP with an IDP.
If you send the SP metadata staticly, validdity time must be removed.
If you send the SP metadata statically, validity time must be removed.
You will also need to register your IDP metadata here either staticly or
You will also need to register your IDP metadata here either statically or
remotely updated.
You may consider testing with testshib.
@ -48,7 +48,7 @@ we wish for without having to do anything ugly. This may require a newer
version of pip than is packaged with distros virtualenv.
Note that this application is python 3 only so you must create your virtualenv
with a python3 interpretter.
with a python3 interpreter.
- ``virtualenv -p `which python3` venv``
- ``source ./venv/bin/activate``

View file

@ -19,20 +19,6 @@ from symposion.proposals.models import ProposalBase
from symposion.schedule.models import Presentation
def score_expression():
score = (
(Decimal(2) * F("plus_two") + F("plus_one")) -
(F("minus_one") + Decimal(2) * F("minus_two"))
) / (
F("vote_count") * Decimal(1)
)
return Case(
When(vote_count=0, then=Value("0")), # no divide by zero
default=score,
)
class Votes(object):
ABSTAIN = "0"
PLUS_TWO = "+2"
@ -196,7 +182,7 @@ class Review(models.Model):
else:
# self is not the latest review so we just need to decrement
# the comment count
self.proposal.result.comment_count = models.F("comment_count") - 1
self.proposal.result.comment_count = F("comment_count") - 1
self.proposal.result.save()
# in all cases we need to delete the review; let's do it!
super(Review, self).delete()
@ -274,6 +260,12 @@ class ProposalResult(models.Model):
result, created = cls._default_manager.get_or_create(proposal=proposal)
result.update_vote()
def calculate_score(self):
if self.vote_count == 0:
return 0
else:
return ((2 * self.plus_two + self.plus_one) - (2 * self.minus_two + self.minus_one)) / self.vote_count
def update_vote(self, *a, **k):
proposal = self.proposal
self.comment_count = Review.objects.filter(proposal=proposal).count()
@ -296,9 +288,8 @@ class ProposalResult(models.Model):
self.minus_one = vote_count[VOTES.MINUS_ONE]
self.minus_two = vote_count[VOTES.MINUS_TWO]
self.vote_count = sum(i[1] for i in vote_count.items()) - self.abstain
self.score = self.calculate_score()
self.save()
model = self.__class__
model._default_manager.filter(pk=self.pk).update(score=score_expression())
class Meta:
verbose_name = _("proposal_result")