def create(form): """Stores a new ticket to the persistent database, and emits it to all connected clients. """ my_ticket = Ticket.for_user(current_user) if my_ticket: return socket_error( 'You are already on the queue', category='warning', ticket_id=my_ticket.ticket_id, ) # Create a new ticket and add it to persistent storage if not (form.get('assignment') and form.get('question') and form.get('location')): return socket_error( 'You must fill out all the fields', category='warning', ) ticket = Ticket( status=TicketStatus.pending, user=current_user, assignment=form.get('assignment'), question=form.get('question'), location=form.get('location'), ) db.session.add(ticket) db.session.commit() emit_event(ticket, TicketEventType.create) return socket_redirect(ticket_id=ticket.id)
def create(form): """Stores a new ticket to the persistent database, and emits it to all connected clients. """ is_closed = ConfigEntry.query.get('is_queue_open') if is_closed.value != 'true': return socket_error( 'The queue is closed', category='warning', ) if not check_magic_word(form.get('magic_word')): return socket_error( 'Invalid magic_word', category='warning', ) my_ticket = Ticket.for_user(current_user) if my_ticket: return socket_error( 'You are already on the queue', category='warning', ticket_id=my_ticket.ticket_id, ) assignment_id = form.get('assignment_id') location_id = form.get('location_id') question = form.get('question') # Create a new ticket and add it to persistent storage if assignment_id is None or location_id is None or not question: return socket_error( 'You must fill out all the fields', category='warning', ) assignment = Assignment.query.get(assignment_id) if not assignment: return socket_error( 'Unknown assignment (id: {})'.format(assignment_id), category='warning', ) location = Location.query.get(location_id) if not location: return socket_error( 'Unknown location (id: {})'.format(location_id), category='warning', ) ticket = Ticket( status=TicketStatus.pending, user=current_user, assignment=assignment, location=location, question=question, ) db.session.add(ticket) db.session.commit() emit_event(ticket, TicketEventType.create) return socket_redirect(ticket_id=ticket.id)
def create_group_ticket(data, group): is_queue_open = ConfigEntry.query.filter_by(course=get_course(), key='is_queue_open').one() if is_queue_open.value != 'true': return socket_error( 'The queue is closed', category='warning', ) if group.ticket and group.ticket.status not in [TicketStatus.resolved, TicketStatus.deleted] or Ticket.for_user(current_user): return socket_error( 'You are already on the queue', category='warning', ) ticket = Ticket( status=TicketStatus.pending, user=current_user, assignment=group.assignment, location=group.location, question=group.question, description="This ticket is associated with a group.", course=get_course(), call_url=group.call_url, doc_url=group.doc_url, ) db.session.add(ticket) db.session.commit() group.ticket = ticket db.session.commit() emit_event(ticket, TicketEventType.create) emit_group_event(group, "group_ticket_created")
def seed(): print('Seeding...') for i in range(50): real_name = names.get_full_name() first_name, last_name = real_name.lower().split(' ') email = '{0}{1}@{2}'.format( random.choice([first_name, first_name[0]]), random.choice([last_name, last_name[0]]), random.choice(['berkeley.edu', 'gmail.com']), ) student = User.query.filter_by(email=email).one_or_none() if not student: student = User(name=real_name, email=email) db.session.add(student) db.session.commit() delta = datetime.timedelta(minutes=random.randrange(0, 30)) ticket = Ticket( user=student, status=TicketStatus.pending, created=datetime.datetime.utcnow() - delta, assignment=random.choice(['Hog', 'Scheme']), description=random.choice(['', 'SyntaxError on Line 5']), question=random.randrange(1, 6), location=random.choice(['109 Morgan', '247 Cory']), ) db.session.add(ticket) db.session.commit()
def seed_data(): print('Seeding...') assignments = [ Assignment(name=name) for name in ['Hog', 'Maps', 'Ants', 'Scheme'] ] locations = [ Location(name=name) for name in ['109 Morgan', '241 Cory', '247 Cory'] ] questions = list(range(1, 16)) + ['Other', 'EC', 'Checkoff'] descriptions = ['', 'I\'m in the hallway', 'SyntaxError on Line 5'] for assignment in assignments: db.session.add(assignment) for location in locations: db.session.add(location) for i in range(50): real_name = names.get_full_name() first_name, last_name = real_name.lower().split(' ') email = '{0}{1}@{2}'.format( random.choice([first_name, first_name[0]]), random.choice([last_name, last_name[0]]), random.choice(['berkeley.edu', 'gmail.com']), ) student = User.query.filter_by(email=email).one_or_none() if not student: student = User(name=real_name, email=email) db.session.add(student) db.session.commit() delta = datetime.timedelta(minutes=random.randrange(0, 30)) ticket = Ticket( user=student, status=TicketStatus.pending, created=datetime.datetime.utcnow() - delta, assignment=random.choice(assignments), location=random.choice(locations), question=random.choice(questions), description=random.choice(descriptions), ) db.session.add(ticket) db.session.commit()
def seed_data(): print('Seeding...') assignments = [Assignment(name=name, course="ok", visible=True) for name in ['Hog', 'Maps', 'Ants', 'Scheme']] locations = [Location(name=name, course="ok", visible=True, online=True, link="") for name in ['109 Morgan', '241 Cory', '247 Cory']] questions = list(range(1, 16)) + ['Other', 'EC', 'Checkoff'] descriptions = ['', 'I\'m in the hallway', 'SyntaxError on Line 5'] students = [] for i in range(50): real_name = names.get_full_name() first_name, last_name = real_name.lower().split(' ') email = '{0}{1}@{2}'.format( random.choice([first_name, first_name[0]]), random.choice([last_name, last_name[0]]), random.choice(['berkeley.edu', 'gmail.com']), ) student = User.query.filter_by(email=email).one_or_none() if not student: student = User(name=real_name, email=email, course="ok") students.append(student) db.session.add(student) db.session.commit() delta = datetime.timedelta(minutes=random.randrange(0, 30)) ticket = Ticket( user=student, status=TicketStatus.pending, created=datetime.datetime.utcnow() - delta, assignment=random.choice(assignments), location=random.choice(locations), question=random.choice(questions), description=random.choice(descriptions), course="ok" ) db.session.add(ticket) appointments = [Appointment( start_time=datetime.datetime.now() + datetime.timedelta(hours=random.randrange(-8, 50)), duration=datetime.timedelta(minutes=random.randrange(30, 120, 30)), location=random.choice(locations), capacity=5, status=AppointmentStatus.pending, course="ok", helper=random.choice(students) ) for _ in range(70)] for assignment in assignments: db.session.add(assignment) for location in locations: db.session.add(location) for appointment in appointments: db.session.add(appointment) db.session.commit() signups = [AppointmentSignup( appointment=random.choice(appointments), user=random.choice(students), assignment=random.choice(assignments), question=random.choice(questions), description=random.choice(descriptions), course="ok", ) for _ in range(120)] for signup in signups: db.session.add(signup) db.session.commit() groups = [ Group( group_status=GroupStatus.active, question=random.choice(questions), assignment=random.choice(assignments), location=random.choice(locations), attendees=[GroupAttendance( user=student, group_attendance_status=GroupAttendanceStatus.present, course="ok" ) for student in random.sample(students, 5)], call_url="", doc_url="", course="ok", ) for _ in range(120)] for group in groups: db.session.add(group) db.session.commit()
def create(form): """Stores a new ticket to the persistent database, and emits it to all connected clients. """ is_closed = ConfigEntry.query.filter_by(course=get_course(), key='is_queue_open').one() if is_closed.value != 'true': return socket_error( 'The queue is closed', category='warning', ) if not check_magic_word(form.get('magic_word')): return socket_error( 'Invalid magic_word', category='warning', ) my_ticket = Ticket.for_user(current_user) if my_ticket: return socket_error( 'You are already on the queue', category='warning', ticket_id=my_ticket.ticket_id, ) assignment_id = form.get('assignment_id') location_id = form.get('location_id') question = form.get('question') description = form.get('description') call_link = form.get('call-link', '') doc_link = form.get('doc-link', '') if call_link: call_link = urljoin("https://", call_link) if doc_link: doc_link = urljoin("https://", doc_link) # Create a new ticket and add it to persistent storage if assignment_id is None or location_id is None or not question: return socket_error( 'You must fill out all the fields', category='warning', ) assignment = Assignment.query.filter_by(course=get_course(), id=assignment_id).one_or_none() if not assignment: return socket_error( 'Unknown assignment (id: {})'.format(assignment_id), category='warning', ) location = Location.query.filter_by(course=get_course(), id=location_id).one_or_none() if not location: return socket_error( 'Unknown location (id: {})'.format(location_id), category='warning', ) ticket = Ticket( status=TicketStatus.pending, user=current_user, assignment=assignment, location=location, question=question, description=description, course=get_course(), call_url=call_link, doc_url=doc_link, ) db.session.add(ticket) db.session.commit() emit_event(ticket, TicketEventType.create) return socket_redirect(ticket_id=ticket.id)
def seed_data(): print("Seeding...") assignments = [ Assignment(name=name, course=get_course(), visible=True) for name in ["Hog", "Maps", "Ants", "Scheme"] ] locations = [ Location(name=name, course=get_course(), visible=True, online=False, link="") for name in ["109 Morgan", "241 Cory", "247 Cory"] ] questions = list(range(1, 16)) + ["Other", "EC", "Checkoff"] descriptions = ["", "I'm in the hallway", "SyntaxError on Line 5"] appointments = [ Appointment( start_time=datetime.datetime.now() + datetime.timedelta(hours=random.randrange(-8, 50)), duration=datetime.timedelta(minutes=random.randrange(30, 120, 30)), location=random.choice(locations), capacity=5, status=AppointmentStatus.pending, course=get_course(), ) for _ in range(70) ] for assignment in assignments: db.session.add(assignment) for location in locations: db.session.add(location) for appointment in appointments: db.session.add(appointment) db.session.commit() students = [] for i in range(50): real_name = names.get_full_name() first_name, last_name = real_name.lower().split(" ") email = "{0}{1}@{2}".format( random.choice([first_name, first_name[0]]), random.choice([last_name, last_name[0]]), random.choice(["berkeley.edu", "gmail.com"]), ) student = User.query.filter_by(email=email).one_or_none() if not student: student = User(name=real_name, email=email, course=get_course()) students.append(student) db.session.add(student) db.session.commit() delta = datetime.timedelta(minutes=random.randrange(0, 30)) ticket = Ticket( user=student, status=TicketStatus.pending, created=datetime.datetime.utcnow() - delta, assignment=random.choice(assignments), location=random.choice(locations), question=random.choice(questions), description=random.choice(descriptions), course=get_course(), ) db.session.add(ticket) signups = [ AppointmentSignup( appointment=random.choice(appointments), user=random.choice(students), assignment=random.choice(assignments), question=random.choice(questions), description=random.choice(descriptions), course=get_course(), ) for _ in range(120) ] for signup in signups: db.session.add(signup) db.session.commit()