Files
@ 101ccd78f099
Branch filter:
Location: CopyleftConf/copyleftconf-website/pinaxcon/templatetags/nbpy_tags.py - annotation
101ccd78f099
3.2 KiB
text/x-python
:qerge branch 'master' into prod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 3053a9bfb232 3053a9bfb232 3053a9bfb232 a0422f0e8433 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 3053a9bfb232 e144ebf41d69 3053a9bfb232 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 d3decadad5bd a0422f0e8433 a0422f0e8433 d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd 27428eeb59ec 27428eeb59ec 27428eeb59ec 1355c0ba83d3 1355c0ba83d3 2e9b94983d40 1355c0ba83d3 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec 27428eeb59ec d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd d3decadad5bd a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 a0422f0e8433 | 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()
@register.simple_tag(takes_context=True)
def donation_income(context, invoice):
''' Calculates the donation income for a given invoice.
Returns:
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 line.product.category.name == "Ticket":
if line.product.name.startswith("Unaffiliated Individual"):
# Includes full price & discounts
rbi.append(line.total_price * fsa_rate)
else:
if line.total_price > 0:
rbi.append(rbi_full_ticket)
elif line.total_price < 0:
rbi.append(rbi_early_bird_discount)
elif line.product.category.name == "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
@register.simple_tag
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.
else:
even_split = len(tokens)
return {
"first" : " ".join(tokens[:even_split]),
"last" : " ".join(tokens[even_split:]),
}
@register.simple_tag
def company_split(name):
f = name_split(name, 18)
return f
@register.simple_tag(takes_context=True)
def special(context, user):
organiser = user.groups.filter(name='Conference organisers').exists()
try:
speaker = user.speaker_profile.presentations.count() != 0
except Exception:
speaker = False
volunteer = "Volunteer" in ticket_type(context)
if organiser:
return "Organizer"
elif speaker:
return "Speaker"
elif volunteer:
return "Staff"
else:
return ""
CLEARED = set([
"BeeWare Project",
"Project Jupyter",
"PSF Packaging WG / PyCon 2018 Chair",
"PyCon Ukraine",
"PyLadies PDX",
"Recovered Silver",
"Twisted",
"@vmbrasseur",
])
@register.simple_tag
def affiliation(ticket, user):
aff = user.attendee.attendeeprofilebase.attendeeprofile.company
if "Individual" not in ticket or "Sponsor" in ticket:
return aff
elif ticket == "Individual Supporter" and aff in CLEARED:
return aff
else:
return ""
@register.simple_tag(takes_context=True)
def ticket_type(context):
items = registrasion_tags.items_purchased(context)
for item in items:
if item.product.category.name == "Ticket":
return item.product.name
|