Example #1
0
def delete(name):
	"""
	Deletes the staff member identified by their name
	"""
	results = process.ERROR_PAGE
	connection = services.getConnection()
	
	name = util.strip(name)
	
	#if the name exsits then delete it
	if services.nameExists(connection, name):
	
		services.deleteStaff(connection, name)
		results = REDIRECT	
	
	return results
Example #2
0
def delete( name, timestamp ):
	"""
	deletes the appointment identified by given timestamp and name
	"""
	results = process.ERROR_PAGE
	datetime = util.toDatetime(timestamp)
	connection = services.getConnection()
	
	#if the data is valid then delete the appointment and redirect to the 
	#main page
	if services.nameExists(connection, name) and datetime:
		
		services.deleteAppointment(connection, datetime, name)
		results = REDIRECT % (util.toDateStr(datetime), datetime.weekday())
	
	connection.close()
	
	return results
Example #3
0
def add(name, roleId, phone, street, city, state, zipCode, isActive=False, oldName=None):
	"""
	Adds or updates a staff member with the information given
	"""
	
	results = process.ERROR_PAGE
	connection = services.getConnection()
	
	try:
		roleId = int(roleId)
	except:
		validData = False
	
	isActive = isActive == "on"	
	
	phone = phone.replace("(", "").replace(")","").replace("-","").replace(" ","")
	name = util.strip(name)
	street = util.strip(street)
	state = util.strip(state).upper()
	zipCode = util.strip(zipCode)

	validData = (len(zipCode) == 0 or len(zipCode) == 5) and (len(state) == 0 or len(state) == 2)
	
	if oldName:
		oldName = util.strip(oldName)
		validData = validData and services.nameExists(connection, oldName)
	
	#if the data is valid then flush it to the database
	if validData:
		
		staff = model.staff.StaffMember(name, roleId, isActive, street, city, state, zipCode, phone)
		
		staff.flush(connection, oldName)
		 
		results = REDIRECT
	
	connection.close()
	
	return results
Example #4
0
def add( date, time, staff, location, desc, addToSupport=False, addToMedical=False, \
oldName=None, oldTime=None, oldDate=None, **kwargs):
	"""
	Checks the given data and if it looks valid then add/update the appointment
	date - the date of the appointment
	time - the time of the appointment
	location - the location
	desc - generic text about the appt
	oldName - the previous person the appt was for
	oldTime - the previous time of the appt
	oldDate - the previous date of the appt
	addToSupport - copy all the information to the support appointment at the
					same time and place
	addToMedical - copy all the information to the medical appointment at the
					same time and place
	kwargs - a collection of optional data (the names of the form field match 
				the names of the appointment fields
	"""
	result = None
	oldTimestamp = None
	date = util.strip(date)
	name = util.strip(staff)
	location = util.strip(location)
	supportAppts = None
	medicalAppts = None

	#set all the optional parameters to None if they are an empty string
	for key,value in kwargs.items():
		if value == "":
			kwargs[key] = None
	
	conn = services.getConnection()
	datetime = util.toDatetime(date, time)

	#check the required data for errors
	validData = services.locationExists(conn, location) \
	and datetime != None and services.nameExists(conn, name) \
	and checkDate(kwargs["lastPeriod"]) \
	and checkDate(kwargs["dateConfirmed"])
	
	#check the old name of the appointment if one was given	
	if oldName:
		oldName= util.strip(oldName)
		validData = validData and services.nameExists(conn, oldName)
	
	#assemble the old timestamp for the appointment if all the information was given
	if oldTime and oldDate:
		oldTimestamp = util.toDatetime(util.strip(oldDate), util.strip(oldTime))
		validData = validData and oldTimestamp != None
	
	#if we are not performing an update then check to see if the new appointment
	#time and person are not already taken
	if not (oldTimestamp == datetime and oldName == staff):
		validData= validData and not services.getAppointment(conn, datetime, staff)

	if addToSupport:
		supportAppts = services.getAppsAtTime(conn, datetime, location, model.role.SUPPORT)
		validData = validData and len(supportAppts)

	if addToMedical:
		medicalAppts = services.getAppsAtTime(conn, datetime, location, model.role.MEDICAL)
		validData = validData and len(medicalAppts)

	#if the data was valid than save it to the database	
	if validData:

		otherAppts = []

		#create the appointment object
		appointment = Appointment(datetime, name, location, None, desc, **kwargs)
		
		#flush the appointment object to the database
		appointment.flush(conn, oldTimestamp, oldName)

		if addToSupport:
			otherAppts += supportAppts	

		if addToMedical:
			otherAppts += medicalAppts

		#add the one extra field that needs to be updated as well
		kwargs["description"] = desc

		#update all the other appointments
		for appt in otherAppts:
			model.updateAll(appt, kwargs)
			appt.flush(conn, appt.time, appt.staffName)

		#set the redirect for the brower
		result = REDIRECT % (date, datetime.weekday())
		
	#else show an error page
	else:
		result = process.ERROR_PAGE

	conn.close()
		
	return result