Files @ 9b48cc94e651
Branch filter:

Location: website/www/conservancy/apps/fundgoal/models.py

Bradley M. Kuhn
Continuing saga of the sizing chart problems for original shirts

Gildan removed the sizing chart entirely from their website again
after yet another redesign. Originally, we deep-linked into files in
their CDN for the charts, but it appears that in 5c72071 that I
introduced cut-and-paste error on the sizing charts. I cannot find
the original links, but finally I simply decided we'd mirror the
files in our CDN, which is where these now link to.

I suspect that I didn't do this to start for worrying about copyright
infringement, but upon second thought, I think it's very reasonably
fair use for us to distribute these images. We bought a lot of
t-shirts from Gildan and just trying to sell through.
from builtins import object
import random

from django.db import models

class FundraisingGoal(models.Model):
    """Conservancy fundraiser Goal"""

    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
    
    class Meta(object):
        ordering = ('fundraiser_code_name',)

    def providers(self):
        return GoalProvider.objects.filter(fundraising_goal=self)

    def random_providers(self, k=None):
        providers = self.providers()
        if not providers.exists():
            return None
        elif k is None:
            return random.choice(providers)
        else:
            return random.sample(providers, k)


class GoalProvider(models.Model):
    fundraising_goal = models.ForeignKey(
        'FundraisingGoal',
        on_delete=models.CASCADE,
    )
    provider_name = models.CharField(max_length=512)

    def __unicode__(self):
        return self.provider_name