Badges work by copy-pasting lca2017/pyconau2017 code around

WIP - Push for share
This commit is contained in:
Sachi King 2017-12-17 16:08:09 +11:00 committed by James Polley
parent 25bff81eab
commit 9ab075e51c
4 changed files with 4343 additions and 15 deletions

View file

@ -30,10 +30,11 @@ else:
DATABASES = {}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
print(DATABASES)
if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql':
DATABASES['default']['OPTIONS'] = {'charset': 'utf8mb4'}
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = os.environ.get('EMAIL_HOST', None)
EMAIL_PORT = os.environ.get('EMAIL_PORT', 25)
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', None)
@ -69,6 +70,8 @@ saml2_contact = {
fail = False
BADGER_DEFAULT_SVG = 'registrasion/badge.svg'
if SECRET_KEY is None:
print("FAILURE: You need to supply a DJANGO_SECRET_KEY "
"environment variable")

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 488 KiB

View file

@ -5,6 +5,7 @@ from django import template
from django.conf import settings
from django.contrib.staticfiles.templatetags import staticfiles
from easy_thumbnails.files import get_thumbnailer
from registrasion.templatetags import registrasion_tags
from symposion.conference import models as conference_models
from symposion.schedule.models import Track
@ -94,3 +95,47 @@ def trackname(room, day):
except Track.DoesNotExist:
track_name = None
return track_name
@register.simple_tag(takes_context=True)
def ticket_type(context):
# Default to purchased ticket type (only item from category 1)
items = registrasion_tags.items_purchased(context, 1)
item = next(iter(items))
name = item.product.name
if name == "Conference Volunteer":
return "Volunteer"
elif name == "Conference Organiser":
return "Organiser"
else:
ticket_type = name
# Miniconfs are secion 2
# General sessions are section 1
user = registrasion_tags.user_for_context(context)
if hasattr(user, "speaker_profile"):
best = 0
for presentation in user.speaker_profile.presentations.all():
if presentation.section.id == 1:
best = 1
if best == 0 and presentation.section.id == 2:
best = 2
if best == 1:
return "Speaker"
elif best == 2:
return "Miniconf Org"
if name == "Sponsor":
return "Professional"
elif name == "Fairy Penguin Sponsor":
return "Professional"
elif name == "Monday and Tuesday Only":
return "Mon/Tue Only"
# Default to product type
return ticket_type

View file

@ -1115,30 +1115,31 @@ def _get_badge_template_name():
@user_passes_test(_staff_only)
def badge(request, user_id):
'''
Renders a single user's badge (SVG).
This does little more than call Richard Jones' collate and svg_badge
functions found in generate_badges.
'''
''' Renders a single user's badge (SVG). '''
user_id = int(user_id)
user = User.objects.get(pk=user_id)
# This will fail spectacularly -- will put exception handling in later ...
user_data = list(collate({'usernames': [user.username]}))[0]
print(type(user))
print(dir(user))
print(user)
orig = etree.parse(_get_badge_template_name())
tree = deepcopy(orig)
root = tree.getroot()
rendered = render_badge(user)
response = HttpResponse(rendered)
svg_badge(root, user_data, 0)
response = HttpResponse(etree.tostring(root))
response["Content-Type"] = "image/svg+xml"
response["Content-Disposition"] = 'inline; filename="badge.svg"'
return response
def render_badge(user):
''' Renders a single user's badge. '''
data = {
"user": user,
}
t = loader.get_template('registrasion/badge.svg')
return t.render(data)
def badges(request):
'''