Badges work by copy-pasting lca2017/pyconau2017 code around
WIP - Push for share
This commit is contained in:
		
							parent
							
								
									25bff81eab
								
							
						
					
					
						commit
						9ab075e51c
					
				
					 4 changed files with 4343 additions and 15 deletions
				
			
		|  | @ -30,10 +30,11 @@ else: | ||||||
| 
 | 
 | ||||||
| DATABASES = {} | DATABASES = {} | ||||||
| DATABASES['default'] = dj_database_url.config(conn_max_age=600) | DATABASES['default'] = dj_database_url.config(conn_max_age=600) | ||||||
|  | print(DATABASES) | ||||||
| if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql': | if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql': | ||||||
|     DATABASES['default']['OPTIONS'] = {'charset': 'utf8mb4'} |     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_HOST = os.environ.get('EMAIL_HOST', None) | ||||||
| EMAIL_PORT = os.environ.get('EMAIL_PORT', 25) | EMAIL_PORT = os.environ.get('EMAIL_PORT', 25) | ||||||
| EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', None) | EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', None) | ||||||
|  | @ -69,6 +70,8 @@ saml2_contact = { | ||||||
| 
 | 
 | ||||||
| fail = False | fail = False | ||||||
| 
 | 
 | ||||||
|  | BADGER_DEFAULT_SVG = 'registrasion/badge.svg' | ||||||
|  | 
 | ||||||
| if SECRET_KEY is None: | if SECRET_KEY is None: | ||||||
|     print("FAILURE: You need to supply a DJANGO_SECRET_KEY " |     print("FAILURE: You need to supply a DJANGO_SECRET_KEY " | ||||||
|           "environment variable") |           "environment variable") | ||||||
|  |  | ||||||
							
								
								
									
										4279
									
								
								pinaxcon/templates/registrasion/badge.svg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4279
									
								
								pinaxcon/templates/registrasion/badge.svg
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| After Width: | Height: | Size: 488 KiB | 
|  | @ -5,6 +5,7 @@ from django import template | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.contrib.staticfiles.templatetags import staticfiles | from django.contrib.staticfiles.templatetags import staticfiles | ||||||
| from easy_thumbnails.files import get_thumbnailer | from easy_thumbnails.files import get_thumbnailer | ||||||
|  | from registrasion.templatetags import registrasion_tags | ||||||
| from symposion.conference import models as conference_models | from symposion.conference import models as conference_models | ||||||
| from symposion.schedule.models import Track | from symposion.schedule.models import Track | ||||||
| 
 | 
 | ||||||
|  | @ -94,3 +95,47 @@ def trackname(room, day): | ||||||
|     except Track.DoesNotExist: |     except Track.DoesNotExist: | ||||||
|         track_name = None |         track_name = None | ||||||
|     return track_name |     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 | ||||||
|  | 
 | ||||||
|  |  | ||||||
							
								
								
									
										29
									
								
								vendor/registrasion/registrasion/views.py
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										29
									
								
								vendor/registrasion/registrasion/views.py
									
										
									
									
										vendored
									
									
								
							|  | @ -1115,30 +1115,31 @@ def _get_badge_template_name(): | ||||||
| 
 | 
 | ||||||
| @user_passes_test(_staff_only) | @user_passes_test(_staff_only) | ||||||
| def badge(request, user_id): | def badge(request, user_id): | ||||||
|     ''' |     ''' Renders a single user's badge (SVG). ''' | ||||||
|     Renders a single user's badge (SVG). |  | ||||||
| 
 |  | ||||||
|     This does little more than call Richard Jones' collate and svg_badge |  | ||||||
|     functions found in generate_badges. |  | ||||||
|     ''' |  | ||||||
| 
 | 
 | ||||||
|     user_id = int(user_id) |     user_id = int(user_id) | ||||||
|     user = User.objects.get(pk=user_id) |     user = User.objects.get(pk=user_id) | ||||||
| 
 | 
 | ||||||
|     # This will fail spectacularly -- will put exception handling in later ... |     print(type(user)) | ||||||
|     user_data = list(collate({'usernames': [user.username]}))[0] |     print(dir(user)) | ||||||
|  |     print(user) | ||||||
| 
 | 
 | ||||||
|     orig = etree.parse(_get_badge_template_name()) |     rendered = render_badge(user) | ||||||
|     tree = deepcopy(orig) |     response = HttpResponse(rendered) | ||||||
|     root = tree.getroot() |  | ||||||
| 
 | 
 | ||||||
|     svg_badge(root, user_data, 0) |  | ||||||
| 
 |  | ||||||
|     response = HttpResponse(etree.tostring(root)) |  | ||||||
|     response["Content-Type"] = "image/svg+xml" |     response["Content-Type"] = "image/svg+xml" | ||||||
|     response["Content-Disposition"] = 'inline; filename="badge.svg"' |     response["Content-Disposition"] = 'inline; filename="badge.svg"' | ||||||
|     return response |     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): | def badges(request): | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Sachi King
						Sachi King