If no boardingpass, make one
- Use the first template in the system - If there's no template, use /tickets/review as it at least gives - people an overview of what they've paid for and warns them of missing categories
This commit is contained in:
		
							parent
							
								
									0bb2f8c25d
								
							
						
					
					
						commit
						7d18387670
					
				
					 2 changed files with 58 additions and 38 deletions
				
			
		|  | @ -36,6 +36,8 @@ | |||
|     you check out:<p> | ||||
|   {% include "registrasion/_items_list.html" with items=pending %} | ||||
| 
 | ||||
|   {% endif %} | ||||
|   <h3>Previously purchased</h3> | ||||
|   {% items_purchased as purchased %} | ||||
|   {% if purchased %} | ||||
|     <p>You've already paid for the following items:</p> | ||||
|  | @ -70,6 +72,7 @@ | |||
| 
 | ||||
|   <h3>What next?</h3> | ||||
| 
 | ||||
|   {% if pending %} | ||||
|   <p>You can either check out an invoice and pay for your selections, or return to | ||||
|       the dashboard.</p> | ||||
| 
 | ||||
|  | @ -77,6 +80,7 @@ | |||
|     <a class="btn btn-success" href="{% url "checkout" %}"> | ||||
|       <i class="fa fa-credit-card"></i> Check out and pay | ||||
|     </a> | ||||
| 
 | ||||
|     <a class="btn btn-primary" href="{% url "dashboard" %}">Return to dashboard</a> | ||||
|   </div> | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										92
									
								
								vendor/regidesk/regidesk/views.py
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										92
									
								
								vendor/regidesk/regidesk/views.py
									
										
									
									
										vendored
									
									
								
							|  | @ -41,8 +41,14 @@ def boardingpass(request): | |||
|     user=request.user | ||||
|     checkin = CheckIn.objects.get_or_create(user=user)[0] | ||||
|     if not checkin.boardingpass: | ||||
|         messages.add_message(request, messages.WARNING, 'Your boarding pass has not been prepared. Please try again later.') | ||||
|         return redirect('/') | ||||
|         templates = BoardingPassTemplate.objects.all() | ||||
|         if not templates: | ||||
|             messages.add_message(request, messages.WARNING, | ||||
|                                  'Your boarding pass has not been prepared and I can\'t find a ' | ||||
|                                  'default template to use. This page has similar information to ' | ||||
|                                  'the boarding pass - please check back later.') | ||||
|             return redirect('/tickets/review') | ||||
|         prepare_boarding_pass(request, templates[0]) | ||||
| 
 | ||||
|     boardingpass = checkin.boardingpass.html_body | ||||
|     qrcode_url = request.build_absolute_uri(reverse("regidesk:checkin_png", args=[checkin.code])) | ||||
|  | @ -170,6 +176,49 @@ def boarding_prepare(request): | |||
| 
 | ||||
|     return response | ||||
| 
 | ||||
| def prepare_boarding_pass(request, template, attendee=None): | ||||
| 
 | ||||
|     if attendee: | ||||
|         user = attendee.user | ||||
|     else: | ||||
|         user = request.user | ||||
|         attendee=user.attendee | ||||
|     checkin = CheckIn.objects.get_or_create(user=user) | ||||
|     ctx = { | ||||
|         "user": user, | ||||
|         "checkin": user.checkin, | ||||
|         "code": user.checkin.code, | ||||
|         "qrcode": user.checkin.qrcode, | ||||
|         "qrcode_url": request.build_absolute_uri( | ||||
|             reverse("regidesk:checkin_png", args=[user.checkin.code])), | ||||
|     } | ||||
|     ctx = Context(ctx) | ||||
|     ctx["invoices"] = invoices(ctx) | ||||
|     ctx["items_pending"] = items_pending(ctx) | ||||
|     ctx["items_purchased"] = items_purchased(ctx) | ||||
|     ctx["missing_categories"] = missing_categories(ctx) | ||||
| 
 | ||||
|     subject = Template(template.subject).render(ctx) | ||||
|     body = Template(template.body).render(ctx) | ||||
|     if template.html_body: | ||||
|         html_body = Template(template.html_body).render(ctx) | ||||
|     else: | ||||
|         html_body = None | ||||
| 
 | ||||
|     bpass = BoardingPass(template=template, to_address=user.email, | ||||
|                          from_address=template.from_address, | ||||
|                          subject=subject, body=body, | ||||
|                          html_body=html_body | ||||
|     ) | ||||
|     bpass.save() | ||||
| 
 | ||||
|     if user.checkin.boardingpass: | ||||
|         user.checkin.boardingpass.delete() | ||||
|     user.checkin.boardingpass = bpass | ||||
|     user.checkin.save() | ||||
| 
 | ||||
|     return body, html_body | ||||
| 
 | ||||
| @permission_required("regidesk.send_boarding_pass") | ||||
| def boarding_send(request): | ||||
| 
 | ||||
|  | @ -190,40 +239,7 @@ def boarding_send(request): | |||
| 
 | ||||
|     for attendee in attendees: | ||||
| 
 | ||||
|         user = attendee.user | ||||
|         checkin = CheckIn.objects.get_or_create(user=user) | ||||
|         ctx = { | ||||
|             "user": user, | ||||
|             "checkin": user.checkin, | ||||
|             "code": user.checkin.code, | ||||
|             "qrcode": user.checkin.qrcode, | ||||
|             "qrcode_url": request.build_absolute_uri( | ||||
|                 reverse("regidesk:checkin_png", args=[user.checkin.code])), | ||||
|         } | ||||
|         ctx = Context(ctx) | ||||
|         ctx["invoices"] = invoices(ctx) | ||||
|         ctx["items_pending"] = items_pending(ctx) | ||||
|         ctx["items_purchased"] = items_purchased(ctx) | ||||
|         ctx["missing_categories"] = missing_categories(ctx) | ||||
| 
 | ||||
|         subject = Template(template.subject).render(ctx) | ||||
|         body = Template(template.body).render(ctx) | ||||
|         if template.html_body: | ||||
|             html_body = Template(template.html_body).render(ctx) | ||||
|         else: | ||||
|             html_body = None | ||||
| 
 | ||||
|         bpass = BoardingPass(template=template, to_address=user.email, | ||||
|                              from_address=template.from_address, | ||||
|                              subject=subject, body=body, | ||||
|                              html_body=html_body | ||||
|         ) | ||||
|         bpass.save() | ||||
| 
 | ||||
|         if user.checkin.boardingpass: | ||||
|             user.checkin.boardingpass.delete() | ||||
|         user.checkin.boardingpass = bpass | ||||
|         user.checkin.save() | ||||
|         body, html_body = prepare_boarding_pass(attendee, template) | ||||
| 
 | ||||
|         msg = EmailMultiAlternatives( | ||||
|             bpass.subject, | ||||
|  | @ -233,8 +249,8 @@ def boarding_send(request): | |||
|         ) | ||||
|         msg.content_subtype="plain" | ||||
|         msg.mixed_subtype="related" | ||||
|         if bpass.html_body: | ||||
|             msg.attach_alternative(bpass.html_body, "text/html") | ||||
|         if html_body: | ||||
|             msg.attach_alternative(html_body, "text/html") | ||||
| 
 | ||||
|         msg.attach(filename="qrcode.png", content=user.checkin.qrcode, mimetype="image/png") | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 James Polley
						James Polley