diff --git a/conservancy/fundgoal/models.py b/conservancy/fundgoal/models.py index 64729cd5..06c3ee93 100644 --- a/conservancy/fundgoal/models.py +++ b/conservancy/fundgoal/models.py @@ -1,3 +1,5 @@ +import datetime +import math import random from django.db import models @@ -10,6 +12,9 @@ class FundraisingGoal(models.Model): fundraiser_goal_amount = models.DecimalField(max_digits=10, decimal_places=2) fundraiser_so_far_amount = models.DecimalField(max_digits=10, decimal_places=2) fundraiser_donation_count = models.IntegerField() + # The number of new Sustainers that can be double-matched this fundraiser. + # (No, this name makes no sense. We're repurposing an existing model field + # for this new reason.) fundraiser_donation_count_disclose_threshold = models.IntegerField() fundraiser_endtime = models.DateTimeField(null=True) @@ -34,6 +39,20 @@ class FundraisingGoal(models.Model): else: return random.sample(providers, k) + def days_remaining(self): + now = datetime.datetime.now() + return (self.fundraiser_endtime - now).days + + def hours_remaining(self): + now = datetime.datetime.now() + return int(math.ceil((self.fundraiser_endtime - now).seconds / 3600)) + + def match_remaining(self): + return self.fundraiser_goal_amount - self.fundraiser_so_far_amount + + def match_exceeded_by(self): + return self.fundraiser_so_far_amount - self.fundraiser_goal_amount + class GoalProvider(models.Model): fundraising_goal = models.ForeignKey( diff --git a/conservancy/fundgoal/templates/fundgoal/fundraiser_goal_banner_partial.html b/conservancy/fundgoal/templates/fundgoal/fundraiser_goal_banner_partial.html index 4814abf6..97a75adb 100644 --- a/conservancy/fundgoal/templates/fundgoal/fundraiser_goal_banner_partial.html +++ b/conservancy/fundgoal/templates/fundgoal/fundraiser_goal_banner_partial.html @@ -1,81 +1,50 @@ {% load humanize %} {% load subtract %} -{% comment %} -# FUNDRAISER VARIABLES AND CONSTANTS GUIDE - -## From Local Context - -* datetime_now: Current DateTime in UTC -* sitefundgoal: The current FundraisingGoal. Attributes: - * fundraiser_goal_amount: The amount being matched - * fundraiser_so_far_amount: The amount contributed so far - * fundraiser_donation_count: The number of people who have contributed so far - * fundraiser_donation_count_disclose_threshold: The number of new Sustainers that can be double-matched this fundraiser. - (No, this name makes no sense. We're repurposing an existing model field for this new reason.) -* sitefundgoal_endtime: DateTime when sitefundgoal ends. - -## Local convenience variables - -* sitefundgoal_timeleft: TimeDelta for how much time remains in the current fundraiser -* this_match_goal: The amount being matched -* this_match_so_far: The amount contributed so far -* this_match_remaining: this_match_goal - this_match_so_far -* this_match_exceeded: this_match_so_far - this_match_goal - -{% endcomment %} -{% with this_match_goal=sitefundgoal.fundraiser_goal_amount this_match_so_far=sitefundgoal.fundraiser_so_far_amount %} -{% with this_match_remaining=this_match_goal|subtract:this_match_so_far sitefundgoal_timeleft=sitefundgoal.fundraiser_endtime|subtract:datetime_now this_match_exceeded=this_match_so_far|subtract:this_match_goal %} - {% if sitefundgoal_timeleft.total_seconds >= -604800 %} -