Changeset - 1ddcb2e4badd
[Not reviewed]
0 3 1
Ben Sturmfels (bsturmfels) - 2 years ago 2021-11-19 06:56:44
ben@sturm.com.au
Move fundraising goal end times into database.
4 files changed with 24 insertions and 13 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/fundgoal/migrations/0003_fundraisinggoal_fundraiser_endtime.py
Show inline comments
 
new file 100644
 
# -*- coding: utf-8 -*-
 
# Generated by Django 1.10.7 on 2021-11-19 01:45
 
from __future__ import unicode_literals
 

	
 
from django.db import migrations, models
 

	
 

	
 
class Migration(migrations.Migration):
 

	
 
    dependencies = [
 
        ('fundgoal', '0002_goalprovider'),
 
    ]
 

	
 
    operations = [
 
        migrations.AddField(
 
            model_name='fundraisinggoal',
 
            name='fundraiser_endtime',
 
            field=models.DateTimeField(null=True),
 
        ),
 
    ]
www/conservancy/apps/fundgoal/models.py
Show inline comments
...
 
@@ -7,12 +7,13 @@ class FundraisingGoal(models.Model):
 

	
 
    fundraiser_code_name = models.CharField(max_length=200, blank=False, unique=True)
 
    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()
 
    fundraiser_donation_count_disclose_threshold = models.IntegerField()
 
    fundraiser_endtime = models.DateTimeField(null=True)
 

	
 
    def __unicode__(self):
 
        return self.fundraiser_code_name
 

	
 
    def percentage_there(self):
 
        return (self.fundraiser_so_far_amount / self.fundraiser_goal_amount ) * 100
www/conservancy/local_context_processors.py
Show inline comments
...
 
@@ -2,33 +2,24 @@ from datetime import datetime as DateTime
 
from pytz import utc as UTC
 

	
 
import conservancy.settings
 
from conservancy.apps.fundgoal.models import FundraisingGoal as FundraisingGoal
 

	
 
SITE_FUNDGOAL = 'cy2021-end-year-match'
 
# FIXME: Move this information into the model.
 
FUNDGOAL_ENDTIMES = {
 
    # Noon UTC = the end of the previous day anywhere on Earth (AOE)
 
    'cy2018-end-year-match': DateTime(2019, 1, 16, 12, tzinfo=UTC),
 
    'cy2019-end-year-match': DateTime(2020, 1, 16, 12, tzinfo=UTC),
 
    'cy2020-end-year-match': DateTime(2021, 1, 16, 12, tzinfo=UTC),
 
    'cy2021-end-year-match': DateTime(2021, 1, 16, 12, tzinfo=UTC),
 
}
 

	
 
def fundgoal_lookup(fundraiser_sought):
 
    try:
 
        return FundraisingGoal.objects.get(fundraiser_code_name=fundraiser_sought)
 
    except FundraisingGoal.DoesNotExist:
 
        # we have no object!  do something
 
        return None
 

	
 
def sitefundraiser(request):
 
    return {
 
        'datetime_now': DateTime.now(UTC),
 
        'datetime_now': DateTime.now(),
 
        'sitefundgoal': fundgoal_lookup(SITE_FUNDGOAL),
 
        'sitefundgoal_endtime': FUNDGOAL_ENDTIMES[SITE_FUNDGOAL],
 
    }
 

	
 
if conservancy.settings.FORCE_CANONICAL_HOSTNAME:
 
    _HOST_URL_VAR = {'host_url': 'https://' + conservancy.settings.FORCE_CANONICAL_HOSTNAME}
 
    def host_url(request):
 
        return _HOST_URL_VAR
www/conservancy/templates/base_conservancy.html
Show inline comments
...
 
@@ -102,16 +102,15 @@
 
* 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
 

	
 
{% endcomment %}
 

	
 
{% if sitefundgoal and sitefundgoal.fundraiser_so_far_amount and datetime_now < sitefundgoal_endtime %}
 
{% if sitefundgoal and sitefundgoal.fundraiser_so_far_amount and datetime_now < sitefundgoal.fundraiser_endtime %}
 
{% 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_endtime|subtract:datetime_now %}
 
{% with this_match_remaining=this_match_goal|subtract:this_match_so_far sitefundgoal_timeleft=sitefundgoal.fundraiser_endtime|subtract:datetime_now %}
 
    <div class="fundraiser-top-text ph3 pt2 pb3">
 
      <div class="mw8 center ph2 ph4-ns">
 
      <div class="mt2 mb3 tc">
 
        {% if this_match_remaining <= 0 %}
 
          Thanks to {{ sitegoal.fundraiser_donation_count|intcomma }} Sustainers we earned our full match!
 
          Help us go further to stand up for software freedom &mdash; <a href="/sustainer">sign up now</a>!
0 comments (0 inline, 0 general)