Coverage for app/controllers/events/routes.py: 44%

36 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-11-22 20:53 +0000

1from flask import Flask, redirect, flash, url_for, request, render_template, g, json, abort, session 

2from datetime import datetime 

3from peewee import DoesNotExist 

4 

5from app.models.term import Term 

6from app.models.program import Program 

7from app.models.event import Event 

8from app.models.eventParticipant import EventParticipant 

9from app.models.user import User 

10from app.controllers.events import events_bp 

11from app.controllers.events import email 

12from app.logic.emailHandler import EmailHandler 

13from app.logic.participants import addBnumberAsParticipant 

14 

15@events_bp.route('/event/<eventid>/kiosk', methods=['GET']) 

16def loadKiosk(eventid): 

17 """Renders kiosk for specified event.""" 

18 event = Event.get_by_id(eventid) 

19 return render_template("/events/eventKiosk.html", 

20 event = event, 

21 eventid = eventid) 

22 

23@events_bp.route('/signintoEvent', methods=['POST']) 

24def kioskSignin(): 

25 """Utilizes form data and sign in function. Returns correct flasher message.""" 

26 eventid = request.form["eventid"] 

27 bnumber = request.form["bNumber"] 

28 

29 if not bnumber: # Avoids string index out of range error 

30 return "", 500 

31 

32 # scanned bNumber starts with ";" and ends with "?" 

33 if bnumber[0]==";" and bnumber[-1]=="?": 

34 bnumber = "B"+ bnumber[1:9] 

35 else: 

36 # regular bnumber with or without a 'B' 

37 if bnumber[0].isdigit(): 

38 bnumber = "B"+ bnumber[0:8] 

39 elif bnumber[0].upper() != "B": 

40 return "", 500 

41 try: 

42 kioskUser, userStatus = addBnumberAsParticipant(bnumber, eventid) 

43 if kioskUser: 

44 return {"user": f"{kioskUser.firstName} {kioskUser.lastName}", "status": userStatus} 

45 else: 

46 return {"user": None, "status": userStatus} 

47 

48 except Exception as e: 

49 print("Error in Kiosk Page", e) 

50 return "", 500