示例#1
0
def event_delete():
    print "I am here"
    emailtobenotified = ""
    event_id = request.form['eventid']
    print event_id
    event_tobe_deleted = Event.query.filter_by(event_id=event_id).one()
    event_tobe_deleted.event_status = "Deleted"
    registration_tobe_deleted = db.session.query(
        Registration.registration_id, Registration.event_id,
        Registration.parent_id, User.email_address).join(User).filter(
            Registration.event_id == event_id,
            Registration.status != 'Cancelled').all()
    if not registration_tobe_deleted:
        print "No registration for this event"
    else:
        registrationdelete = db.session.query(Registration).filter(
            Registration.event_id == event_id,
            Registration.status != 'Cancelled').all()
        for regi in registration_tobe_deleted:
            registration = Registration.query.get(regi.registration_id)
            registration.status = "Deleted"
            emailtobenotified += regi.email_address
            print emailtobenotified
            eventmessage = {}
            eventmessage['eventname'] = event_tobe_deleted.event_name
            eventmessage['eventdate'] = event_tobe_deleted.event_date.strftime(
                "%B %d, %Y")
            eventmessage['eventdesc'] = event_tobe_deleted.event_description

            # print eventmessage

            # print ('before sending email template email')

            templateobj = EmailTemplate(template_name='cancellation.txt',
                                        values=eventmessage)
            message = templateobj.render()
            print "I am here ********************************************"
            send_notification(regi.email_address, registerDelete, message)

    db.session.commit()

    event_record = Event.query.filter_by(event_id=event_id).one()

    print "Reached till here #################################"
    return jsonify(eventid=event_record.event_id,
                   eventstatus=event_record.event_status)
示例#2
0
def event_delete():
	print "I am here"
	emailtobenotified=""
	event_id = request.form['eventid']
	print event_id
	event_tobe_deleted = Event.query.filter_by(event_id=event_id).one()
	event_tobe_deleted.event_status = "Deleted"
	registration_tobe_deleted = db.session.query(Registration.registration_id,Registration.event_id,Registration.parent_id,User.email_address).join(User).filter(Registration.event_id==event_id,Registration.status != 'Cancelled').all()	
	if not registration_tobe_deleted:
		print "No registration for this event"
	else:
		registrationdelete = db.session.query(Registration).filter(Registration.event_id==event_id,Registration.status != 'Cancelled').all()
		for regi in registration_tobe_deleted:
			registration = Registration.query.get(regi.registration_id)
			registration.status ="Deleted"
			emailtobenotified+= regi.email_address
			print emailtobenotified
			eventmessage = {}
			eventmessage['eventname'] = event_tobe_deleted.event_name
			eventmessage['eventdate'] = event_tobe_deleted.event_date.strftime("%B %d, %Y")
			eventmessage['eventdesc'] = event_tobe_deleted.event_description
 		
 		# print eventmessage

 		# print ('before sending email template email')

			templateobj = EmailTemplate(template_name='cancellation.txt', values=eventmessage)
			message = templateobj.render()
			print "I am here ********************************************"
			send_notification(regi.email_address,registerDelete,message)
	
	db.session.commit()

	event_record = Event.query.filter_by(event_id=event_id).one()

	print "Reached till here #################################"
	return jsonify(eventid = event_record.event_id,eventstatus =event_record.event_status  )
示例#3
0
def admin_page():
	"""Update Admin changes to our database."""

	# print "I am in the method"
	#import pdb; pdb.set_trace()

	event_id = request.form.get("eventid")
	event_name = request.form.get("eventname")
	event_date = request.form.get("eventdate")
	event_description = request.form.get("eventdesc")
	event_status = request.form.get("eventstatus")
	event_spots = request.form.get("noofspots")
	print "*********************************************************"
	print event_id
	print event_name
	print datetime
	print event_description
	print event_status
	print event_spots
	print "*********************************************************"
	print event_id , event_name,event_date,event_description,event_status,event_spots
	event_count = Event.query.filter_by(event_id=event_id).count()
	print event_count
	if event_count == 0 :
		new_event = Event(event_name=event_name,event_date=datetime.strptime(event_date , '%Y-%m-%d'),event_length=1,event_description=event_description,event_status=event_status,no_of_spots=event_spots,no_of_reg_spots=0,no_of_waitlist_spots=0,recurring='Yes' ,created_id=500 )
		print "I am inside insert *****************************"
		print event_name
		print event_date
		print event_description
		print event_status
		print event_spots
		print "########*********************************************************"

		eventmessage = {}
		eventmessage['eventname'] = event_name
		eventmessage['eventdate'] = event_date
		eventmessage['eventdesc'] = event_description
		print "*********************************************************########"
		
		db.session.add(new_event)

		db.session.commit()
		
		print eventmessage

		templateobj = EmailTemplate(template_name='eventadd.txt', values=eventmessage)
		message = templateobj.render()

 		usertobenotified = User.query.filter_by(reminder="Yes").all()

		for user in usertobenotified:
			print user.email_address
			send_notification(user.email_address,Eventadd,message)
 		
		print message
		create_event(event_name,event_date,event_description)
 		# print eventmessage

 		# print ('before sending email template email')

		print "I am here ********************************************"
	
		return "The event is updated"

	else:

		change_event = Event.query.get(event_id)
		change_event.event_id = event_id
		change_event.event_name=event_name
		change_event.event_date=datetime.strptime(event_date , '%Y-%m-%d')
		change_event.event_length=1
		change_event.event_description=event_description
		change_event.event_status=event_status
		change_event.no_of_spots=event_spots
		change_event.recurring = 'Yes'
		change_event.created_id = 500

		#admin_event = Event(event_id = event_id,event_name=event_name,event_date=datetime.now(),event_length=1,event_description=event_description,event_status=event_status,no_of_spots=event_spots,recurring = 'Yes', created_id=500)
		#db.session.add(admin_event)
		db.session.commit()
		# print event_id , event_name,event_date,event_description,event_status,event_spots
		return "The event is updated"
示例#4
0
def signup_process():
	"""Add Event signup order to our database."""
	# Decoding the JSON object getting from the 
	parent_id = request.form['userid']
	event_id = request.form['eventid']
	op = request.form['opcode']

	# print "Activity id i populated below"
	# print event_id
	# print op

	if op == "register":

		#updating - increment the no_of_reg_spots by 1 in the database column no_of_reg_spots
		register_event = Registration(parent_id=parent_id, event_id=event_id,slot_id=1,registration_date = datetime.now(),status = 'Registered',showup="")
		db.session.add(register_event)
		update_no_of_reg_spots = Event.query.get(event_id)
		update_no_of_reg_spots.no_of_reg_spots += 1
		db.session.commit()
	    
		# Integrating the Gmail API and making a call to the mailer
		# print session["email"]
		# print ('before sending Register email')
		
		eventmessage = {}
		eventmessage['eventname'] = update_no_of_reg_spots.event_name
		eventmessage['eventdate'] = update_no_of_reg_spots.event_date.strftime("%B %d, %Y")
		eventmessage['eventdesc'] = update_no_of_reg_spots.event_description
 		
 		# print eventmessage

 		# print ('before sending email template email')

		templateobj = EmailTemplate(template_name='registration.txt', values=eventmessage)
		message = templateobj.render()

		print ('before sending before actual email')

		print registerSub
		print message

		send_notification(session["email"],registerSub,message)

		print ('before sending Register email')

		# user_registration = Registration.query.filter_by(parent_id=parent).subquery()
		# signupObj = {}
		# sign_up = db.session.query(Event.event_id,Event.event_name,Event.event_description,Event.event_date,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
		# for item in sign_up:
		# 	# signupObj["event_id"] = item.event_id
		# 	# signupObj["event_name"] = item.event_name
		# 	# signupObj["event_description"] = item.event_description
		# 	# signupObj["event_date"] = item.event_date
		# 	# signupObj["no_of_remaining_spots"] = item.no_of_remaining_spots
		# 	signupObj["status"] = item.status


		#print signupObj
		#print jsonify(register_event)
		
		print "jsonyfy works"
		user_registration = Registration.query.filter_by(parent_id=session["user_id"]).subquery()
		sign_up = db.session.query(Event.event_id,Event.no_of_waitlist_spots,Event.event_name,Event.event_description,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
		#print jsonify(dumps(sign_up))

		for i in sign_up:
			x = i
			print x.no_of_waitlist_spots

		return jsonify(json_list = x )


		#return jsonify(register_event)

	# print "Shilpa updating count"
	# print update_no_of_reg_spots.no_of_reg_spots
	elif op == "waitlist":

		#updating - increment the no_of_waitlisted_spots by 1 in the database column no_of_reg_spots
		register_event = Registration(parent_id=parent_id, event_id=event_id,slot_id=1,registration_date = datetime.now(),status = 'Waitlisted',showup="")
		db.session.add(register_event)
		update_no_of_waitlist_spots = Event.query.get(event_id)
		update_no_of_waitlist_spots.no_of_waitlist_spots += 1
		db.session.commit()
		# print "I am in waitlist"
	    
		
		# print session["email"]
		# print ('before sending Register email')
		
		eventmessage = {}
		eventmessage['eventname'] = update_no_of_waitlist_spots.event_name
		eventmessage['eventdate'] = update_no_of_waitlist_spots.event_date.strftime("%B %d, %Y")
		eventmessage['eventdesc'] = update_no_of_waitlist_spots.event_description
 		
 		# print eventmessage

 		# print ('before sending email template email')

		templateobj = EmailTemplate(template_name='waitlist.txt', values=eventmessage)
		message = templateobj.render()

		# print ('before sending before actual email')

		# print registerSub
		# print message

		# Integrating the Gmail API and making a call to the mailer
		send_notification(session["email"],registerSub,message)

		print ('before sending Register email')

		# user_registration = Registration.query.filter_by(parent_id=parent).subquery()
		# signupObj = {}
		# sign_up = db.session.query(Event.event_id,Event.event_name,Event.event_description,Event.event_date,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
		# for item in sign_up:
		# 	# signupObj["event_id"] = item.event_id
		# 	# signupObj["event_name"] = item.event_name
		# 	# signupObj["event_description"] = item.event_description
		# 	# signupObj["event_date"] = item.event_date
		# 	# signupObj["no_of_remaining_spots"] = item.no_of_remaining_spots
		# 	signupObj["status"] = item.status


		#print signupObj
		#print jsonify(register_event)
		
		# print "jsonyfy works"
		user_registration = Registration.query.filter_by(parent_id=session["user_id"]).subquery()
		sign_up = db.session.query(Event.event_id,Event.no_of_waitlist_spots,Event.event_name,Event.event_description,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
		#print jsonify(dumps(sign_up))

		for i in sign_up:
			x = i
			# print x.no_of_waitlist_spots

		return jsonify(json_list = x )

		#return jsonify(register_event)

		# print "Shilpa updating count"
		# print update_no_of_reg_spots.no_of_reg_spots
	else:
		#Checking if the op = "cancel"
		print "Inside else block"
		print event_id
		print parent_id

		update_reg_status = Registration.query.filter_by(event_id=event_id,parent_id=parent_id).one()
		update_reg_status.status = 'Cancelled'
		# Finding the minimum reistration for an event id with waitlisted status
		waitlisted_regid = db.session.query(func.min(Registration.registration_id).label('min_reg_id')).filter( event_id==event_id,Registration.status == 'Waitlisted').one()
		# Bringing the whole record(object)
		# When the cancel is happening
		# update the database column no_of_spots decrement by 1
		# If a user is not in the waitlist
		if  waitlisted_regid:
			print "I am in null"
			update_no_of_spots = Event.query.get(event_id)
			update_no_of_spots.no_of_reg_spots -= 1
		else :
			#moving from waitlisted to registration action
			#decrement waitlist spots by 1
			#increment no of registered spots by 1
			who_is_waitlisted = Registration.query.filter(Registration.registration_id== waitlisted_regid.min_reg_id ).one()
			who_is_waitlisted.status = 'Registered'
			update_no_of_waitspots = Event.query.get(event_id)
			update_no_of_waitspots.no_of_waitlist_spots -=1
			who_is_waitlisted_user = User.query.filter_by(user_id = who_is_waitlisted.parent_id).one()
			sms_message = "Dear "+who_is_waitlisted_user.first_name+" "+who_is_waitlisted_user.last_name+" Your reservaton for event "+update_no_of_waitspots.event_name+" on "+update_no_of_waitspots.event_date.strftime("%B %d, %Y")+" has bee confirmed. Please make changes by signing to MySignUp application. Enjoy and Engage with kids - MySignUp Team"
			send_twillio_sms(sms_message,who_is_waitlisted_user.phone_number)
		db.session.commit()
	    
		# Integrating the Gmail API and making a call to the mailer
		# print session["email"]
		# print ('before sending cancelling ****** email')

		eventmessage = {}
		eventmessage['eventname'] = update_no_of_spots.event_name
		eventmessage['eventdate'] = update_no_of_spots.event_date.strftime("%B %d, %Y")
		eventmessage['eventdesc'] = update_no_of_spots.event_description
 		
 		# print eventmessage

 		# print ('before sending email template email')

		templateobj = EmailTemplate(template_name='cancellation.txt', values=eventmessage)
		message = templateobj.render()

		# print ('before sending before actual email')

		# Integrating the Gmail API and making a call to the mailer
		send_notification(session["email"],registerCancel,message)


		#send_notification(session["email"],'You are all set for baking','Test the function')
		print "jsonyfy works"
		user_registration = Registration.query.filter_by(parent_id=session["user_id"]).subquery()
		sign_up = db.session.query(Event.event_id,Event.no_of_waitlist_spots,Event.event_name,Event.event_description,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
		#print jsonify(dumps(sign_up))
		# 
		for i in sign_up:
			x = i
			# print x
			# print x.no_of_waitlist_spots
		# x is the tuple that needs to be jsonified(as key-value pairs) to give to javascript
		return jsonify(json_list = x )
示例#5
0
def admin_page():
    """Update Admin changes to our database."""

    # print "I am in the method"
    #import pdb; pdb.set_trace()

    event_id = request.form.get("eventid")
    event_name = request.form.get("eventname")
    event_date = request.form.get("eventdate")
    event_description = request.form.get("eventdesc")
    event_status = request.form.get("eventstatus")
    event_spots = request.form.get("noofspots")
    print "*********************************************************"
    print event_id
    print event_name
    print datetime
    print event_description
    print event_status
    print event_spots
    print "*********************************************************"
    print event_id, event_name, event_date, event_description, event_status, event_spots
    event_count = Event.query.filter_by(event_id=event_id).count()
    print event_count
    if event_count == 0:
        new_event = Event(event_name=event_name,
                          event_date=datetime.strptime(event_date, '%Y-%m-%d'),
                          event_length=1,
                          event_description=event_description,
                          event_status=event_status,
                          no_of_spots=event_spots,
                          no_of_reg_spots=0,
                          no_of_waitlist_spots=0,
                          recurring='Yes',
                          created_id=500)
        print "I am inside insert *****************************"
        print event_name
        print event_date
        print event_description
        print event_status
        print event_spots
        print "########*********************************************************"

        eventmessage = {}
        eventmessage['eventname'] = event_name
        eventmessage['eventdate'] = event_date
        eventmessage['eventdesc'] = event_description
        print "*********************************************************########"

        db.session.add(new_event)

        db.session.commit()

        print eventmessage

        templateobj = EmailTemplate(template_name='eventadd.txt',
                                    values=eventmessage)
        message = templateobj.render()

        usertobenotified = User.query.filter_by(reminder="Yes").all()

        for user in usertobenotified:
            print user.email_address
            send_notification(user.email_address, Eventadd, message)

        print message
        create_event(event_name, event_date, event_description)
        # print eventmessage

        # print ('before sending email template email')

        print "I am here ********************************************"

        return "The event is updated"

    else:

        change_event = Event.query.get(event_id)
        change_event.event_id = event_id
        change_event.event_name = event_name
        change_event.event_date = datetime.strptime(event_date, '%Y-%m-%d')
        change_event.event_length = 1
        change_event.event_description = event_description
        change_event.event_status = event_status
        change_event.no_of_spots = event_spots
        change_event.recurring = 'Yes'
        change_event.created_id = 500

        #admin_event = Event(event_id = event_id,event_name=event_name,event_date=datetime.now(),event_length=1,event_description=event_description,event_status=event_status,no_of_spots=event_spots,recurring = 'Yes', created_id=500)
        #db.session.add(admin_event)
        db.session.commit()
        # print event_id , event_name,event_date,event_description,event_status,event_spots
        return "The event is updated"
示例#6
0
def signup_process():
    """Add Event signup order to our database."""
    # Decoding the JSON object getting from the
    parent_id = request.form['userid']
    event_id = request.form['eventid']
    op = request.form['opcode']

    # print "Activity id i populated below"
    # print event_id
    # print op

    if op == "register":

        #updating - increment the no_of_reg_spots by 1 in the database column no_of_reg_spots
        register_event = Registration(parent_id=parent_id,
                                      event_id=event_id,
                                      slot_id=1,
                                      registration_date=datetime.now(),
                                      status='Registered',
                                      showup="")
        db.session.add(register_event)
        update_no_of_reg_spots = Event.query.get(event_id)
        update_no_of_reg_spots.no_of_reg_spots += 1
        db.session.commit()

        # Integrating the Gmail API and making a call to the mailer
        # print session["email"]
        # print ('before sending Register email')

        eventmessage = {}
        eventmessage['eventname'] = update_no_of_reg_spots.event_name
        eventmessage['eventdate'] = update_no_of_reg_spots.event_date.strftime(
            "%B %d, %Y")
        eventmessage['eventdesc'] = update_no_of_reg_spots.event_description

        # print eventmessage

        # print ('before sending email template email')

        templateobj = EmailTemplate(template_name='registration.txt',
                                    values=eventmessage)
        message = templateobj.render()

        print('before sending before actual email')

        print registerSub
        print message

        send_notification(session["email"], registerSub, message)

        print('before sending Register email')

        # user_registration = Registration.query.filter_by(parent_id=parent).subquery()
        # signupObj = {}
        # sign_up = db.session.query(Event.event_id,Event.event_name,Event.event_description,Event.event_date,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
        # for item in sign_up:
        # 	# signupObj["event_id"] = item.event_id
        # 	# signupObj["event_name"] = item.event_name
        # 	# signupObj["event_description"] = item.event_description
        # 	# signupObj["event_date"] = item.event_date
        # 	# signupObj["no_of_remaining_spots"] = item.no_of_remaining_spots
        # 	signupObj["status"] = item.status

        #print signupObj
        #print jsonify(register_event)

        print "jsonyfy works"
        user_registration = Registration.query.filter_by(
            parent_id=session["user_id"]).subquery()
        sign_up = db.session.query(
            Event.event_id, Event.no_of_waitlist_spots, Event.event_name,
            Event.event_description, Event.event_status,
            label('no_of_remaining_spots',
                  Event.no_of_spots - Event.no_of_reg_spots),
            user_registration.c.parent_id,
            user_registration.c.status).outerjoin(
                user_registration,
                Event.event_id == user_registration.c.event_id).filter(
                    Event.event_date >= date.today(),
                    Event.event_id == event_id).all()
        #print jsonify(dumps(sign_up))

        for i in sign_up:
            x = i
            print x.no_of_waitlist_spots

        return jsonify(json_list=x)

        #return jsonify(register_event)

    # print "Shilpa updating count"
    # print update_no_of_reg_spots.no_of_reg_spots
    elif op == "waitlist":

        #updating - increment the no_of_waitlisted_spots by 1 in the database column no_of_reg_spots
        register_event = Registration(parent_id=parent_id,
                                      event_id=event_id,
                                      slot_id=1,
                                      registration_date=datetime.now(),
                                      status='Waitlisted',
                                      showup="")
        db.session.add(register_event)
        update_no_of_waitlist_spots = Event.query.get(event_id)
        update_no_of_waitlist_spots.no_of_waitlist_spots += 1
        db.session.commit()
        # print "I am in waitlist"

        # print session["email"]
        # print ('before sending Register email')

        eventmessage = {}
        eventmessage['eventname'] = update_no_of_waitlist_spots.event_name
        eventmessage[
            'eventdate'] = update_no_of_waitlist_spots.event_date.strftime(
                "%B %d, %Y")
        eventmessage[
            'eventdesc'] = update_no_of_waitlist_spots.event_description

        # print eventmessage

        # print ('before sending email template email')

        templateobj = EmailTemplate(template_name='waitlist.txt',
                                    values=eventmessage)
        message = templateobj.render()

        # print ('before sending before actual email')

        # print registerSub
        # print message

        # Integrating the Gmail API and making a call to the mailer
        send_notification(session["email"], registerSub, message)

        print('before sending Register email')

        # user_registration = Registration.query.filter_by(parent_id=parent).subquery()
        # signupObj = {}
        # sign_up = db.session.query(Event.event_id,Event.event_name,Event.event_description,Event.event_date,Event.event_status,label('no_of_remaining_spots',Event.no_of_spots - Event.no_of_reg_spots),user_registration.c.parent_id,user_registration.c.status).outerjoin(user_registration,Event.event_id==user_registration.c.event_id).filter(Event.event_date >= date.today(), Event.event_id == event_id ).all()
        # for item in sign_up:
        # 	# signupObj["event_id"] = item.event_id
        # 	# signupObj["event_name"] = item.event_name
        # 	# signupObj["event_description"] = item.event_description
        # 	# signupObj["event_date"] = item.event_date
        # 	# signupObj["no_of_remaining_spots"] = item.no_of_remaining_spots
        # 	signupObj["status"] = item.status

        #print signupObj
        #print jsonify(register_event)

        # print "jsonyfy works"
        user_registration = Registration.query.filter_by(
            parent_id=session["user_id"]).subquery()
        sign_up = db.session.query(
            Event.event_id, Event.no_of_waitlist_spots, Event.event_name,
            Event.event_description, Event.event_status,
            label('no_of_remaining_spots',
                  Event.no_of_spots - Event.no_of_reg_spots),
            user_registration.c.parent_id,
            user_registration.c.status).outerjoin(
                user_registration,
                Event.event_id == user_registration.c.event_id).filter(
                    Event.event_date >= date.today(),
                    Event.event_id == event_id).all()
        #print jsonify(dumps(sign_up))

        for i in sign_up:
            x = i
            # print x.no_of_waitlist_spots

        return jsonify(json_list=x)

        #return jsonify(register_event)

        # print "Shilpa updating count"
        # print update_no_of_reg_spots.no_of_reg_spots
    else:
        #Checking if the op = "cancel"
        print "Inside else block"
        print event_id
        print parent_id

        update_reg_status = Registration.query.filter_by(
            event_id=event_id, parent_id=parent_id).one()
        update_reg_status.status = 'Cancelled'
        # Finding the minimum reistration for an event id with waitlisted status
        waitlisted_regid = db.session.query(
            func.min(Registration.registration_id).label('min_reg_id')).filter(
                event_id == event_id,
                Registration.status == 'Waitlisted').one()
        # Bringing the whole record(object)
        # When the cancel is happening
        # update the database column no_of_spots decrement by 1
        # If a user is not in the waitlist
        if waitlisted_regid:
            print "I am in null"
            update_no_of_spots = Event.query.get(event_id)
            update_no_of_spots.no_of_reg_spots -= 1
        else:
            #moving from waitlisted to registration action
            #decrement waitlist spots by 1
            #increment no of registered spots by 1
            who_is_waitlisted = Registration.query.filter(
                Registration.registration_id ==
                waitlisted_regid.min_reg_id).one()
            who_is_waitlisted.status = 'Registered'
            update_no_of_waitspots = Event.query.get(event_id)
            update_no_of_waitspots.no_of_waitlist_spots -= 1
            who_is_waitlisted_user = User.query.filter_by(
                user_id=who_is_waitlisted.parent_id).one()
            sms_message = "Dear " + who_is_waitlisted_user.first_name + " " + who_is_waitlisted_user.last_name + " Your reservaton for event " + update_no_of_waitspots.event_name + " on " + update_no_of_waitspots.event_date.strftime(
                "%B %d, %Y"
            ) + " has bee confirmed. Please make changes by signing to MySignUp application. Enjoy and Engage with kids - MySignUp Team"
            send_twillio_sms(sms_message, who_is_waitlisted_user.phone_number)
        db.session.commit()

        # Integrating the Gmail API and making a call to the mailer
        # print session["email"]
        # print ('before sending cancelling ****** email')

        eventmessage = {}
        eventmessage['eventname'] = update_no_of_spots.event_name
        eventmessage['eventdate'] = update_no_of_spots.event_date.strftime(
            "%B %d, %Y")
        eventmessage['eventdesc'] = update_no_of_spots.event_description

        # print eventmessage

        # print ('before sending email template email')

        templateobj = EmailTemplate(template_name='cancellation.txt',
                                    values=eventmessage)
        message = templateobj.render()

        # print ('before sending before actual email')

        # Integrating the Gmail API and making a call to the mailer
        send_notification(session["email"], registerCancel, message)

        #send_notification(session["email"],'You are all set for baking','Test the function')
        print "jsonyfy works"
        user_registration = Registration.query.filter_by(
            parent_id=session["user_id"]).subquery()
        sign_up = db.session.query(
            Event.event_id, Event.no_of_waitlist_spots, Event.event_name,
            Event.event_description, Event.event_status,
            label('no_of_remaining_spots',
                  Event.no_of_spots - Event.no_of_reg_spots),
            user_registration.c.parent_id,
            user_registration.c.status).outerjoin(
                user_registration,
                Event.event_id == user_registration.c.event_id).filter(
                    Event.event_date >= date.today(),
                    Event.event_id == event_id).all()
        #print jsonify(dumps(sign_up))
        #
        for i in sign_up:
            x = i
            # print x
            # print x.no_of_waitlist_spots
        # x is the tuple that needs to be jsonified(as key-value pairs) to give to javascript
        return jsonify(json_list=x)