Esempio n. 1
0
def membership_year_start(request):
    today = date.today()
    date_set = {}
    for key, value in membership_year_start_date_set().items():
        date_set[key] = {
            'date': value,
            'has_passed': today >= value,
            'applicable_year': value.year + 1 if today >= value else today.year
        }
    return {'membership_year_start': date_set}
def nearing_membership_year_end(request):
    """
    When we're nearing the end of the membership year, enrollments and gift memberships get less relevant. Most
    members will want to the end of the membership year (typically the first of October/November) and then receive
    membership for the remainder of the year, AND the next year. This context variable is True when we feel that the
    end of the year is approaching and might want to hint to our users about this situation.
    """
    DAYS_REMAINING_LIMIT = 60  # This number is pretty much pulled out of the air
    days_remaining = (membership_year_start_date_set()["public_date"] - date.today()).days
    nearing_membership_year_end = days_remaining <= DAYS_REMAINING_LIMIT and days_remaining >= 0
    return {"nearing_membership_year_end": nearing_membership_year_end}
def membership_year_start(request):
    """
    Returns a dict with information about the current state of the membership year. Contains 3 dicts:
    - initiation_date
    - applicable_year
    - public_date

    Each of those dicts contain the following keys:
    - date: The date when this event occurs
    - has_passed: True if the event occured earlier this year
    - applicable_year: The current year if the date hasn't passed; otherwise the next year

    For more info, see:
    - settings.MEMBERSHIP_YEAR_START variable
    - core.util.membership_year_start method

    For example, if the current date is 2015-10-29:
    {'initiation_date': {
        'applicable_year': 2016,
        'date': datetime.date(2015, 10, 15),
        'has_passed': True,
    }, 'actual_date': {
        'applicable_year': 2016,
        'date': datetime.date(2015, 10, 27),
        'has_passed': True,
    }, 'public_date': {
        'applicable_year': 2015,
        'date': datetime.date(2015, 11, 1),
        'has_passed': False,
    }}
    """
    today = date.today()
    date_set = {}
    for key, value in membership_year_start_date_set().items():
        date_set[key] = {
            "date": value,
            "has_passed": today >= value,
            "applicable_year": value.year + 1 if today >= value else today.year,
        }
    return {"membership_year_start": date_set}