Files @ 1aafae38434b
Branch filter:

Location: CopyleftConf/copyleftconf-website/pinaxcon/templatetags/

Christopher Neugebauer
Speaker profile may be none
from registrasion.models import commerce
from registrasion.controllers.category import CategoryController
from registrasion.controllers.item import ItemController
from registrasion.templatetags import registrasion_tags

from decimal import Decimal
from django import template
from django.conf import settings
from django.db.models import Sum
from urllib import urlencode  # TODO: s/urllib/six.moves.urllib/

register = template.Library()

def donation_income(context, invoice):
    ''' Calculates the donation income for a given invoice.

        the donation income.


    # 15% (FSA) goes to Conservancy; 85% is real goods

    fsa_rate = Decimal("0.85")
    rbi_full_ticket = Decimal("68.00")
    rbi_early_bird_discount = Decimal("-21.35")
    rbi = []

    for line in invoice.lineitem_set.all():
        if == "Ticket":
            if"Unaffiliated Individual"):
                # Includes full price & discounts
                rbi.append(line.total_price * fsa_rate)
                if line.total_price > 0:
                elif line.total_price < 0:
        elif == "T-Shirt":
            rbi.append(line.total_price * fsa_rate)

    donation = max(Decimal('0'), (invoice.value - sum(rbi)))
    return donation.quantize(Decimal('.01'))

# TODO: include van/de/van der/de la/etc etc etc

def name_split(name, split_characters=None):

    tokens = name.split()
    if split_characters is None or len(name) > split_characters:
        even_split = int((len(tokens) + 1) / 2)  # Round up.
        even_split = len(tokens)

    return {
        "first" : " ".join(tokens[:even_split]),
        "last" : " ".join(tokens[even_split:]),

def company_split(name):
    f =  name_split(name, 18)
    return f

def special(context, user):
    organiser = user.groups.filter(name='Conference organisers').exists()
    speaker = if user.speaker_profile and user.speaker_profile.presentations.count() != 0
    volunteer = "Volunteer" in ticket_type(context)

    if organiser:
        return "Organizer"
    elif speaker:
        return "Speaker"
    elif volunteer:
        return "Staff"
        return ""

CLEARED = set([
    "BeeWare Project",
    "Project Jupyter",
    "PSF Packaging WG / PyCon 2018 Chair",
    "PyCon Ukraine",
    "PyLadies PDX",
    "Recovered Silver",

def affiliation(ticket, user):
    aff =
    if "Individual" not in ticket or "Sponsor" in ticket:
        return aff
    elif ticket == "Individual Supporter" and aff in CLEARED:
        return aff
        return ""

def ticket_type(context):

    items = registrasion_tags.items_purchased(context)
    for item in items:
        if == "Ticket":