Example #1
0
def buildDay(locations, roles, appMap, theDate):
	"""
	Builds HTML to represent a given day
	"""
	result = """<table id=\"%s\" class="schedule">
	<tr>
		<th></th> <th colspan=\"3\"><a href=\"dayDetails?date=%s&location=%s\">Albany</a></th> 
		<th colspan=\"3\"><a href=\"dayDetails?date=%s&location=%s\">Corvallis</a></th>
	</tr>
	<tr>
		<th>%s</th> <th>Advocate</th> <th>Support</th> <th>Medical</th>
		<th>Advocate</th> <th>Support</th> <th>Medical</th>
	</tr>""" % (util.toDayName(theDate), util.startOfWeek(theDate), model.LOC1, util.startOfWeek(theDate), model.LOC2, util.toDateStr(theDate,True)) #e.g. Monday, 1/3

	base =  ""
	
	#for each hour in the day build the associated html
	for i,timeslot in enumerate(sorted( appMap.keys(), compareTimes )):
		result += buildSlot(locations, roles, appMap[timeslot], theDate, timeslot, not(i % 2))

	#build the default time
	defaultTime = util.toDatetime(util.toDateStr(theDate),DEFAULT_TIME)

	#build the base of the day
	for loc in locations:
		for role in roles:
			base += ADD_TEMPLATE % (role.roleId, loc, defaultTime) 

	return result + "<tr><td></td>" + base + "</tr></table>\n"
Example #2
0
def build(locations, roles, schedule, startDate, tab):
	"""
	Formats the given data and generates the html page
	"""
	calendar = ""

	def curTab(day):
		return "curTab" if day == tab else "tab"

	params = { "%PREV_WEEK%":util.startOfPrevWeek(startDate),
	"%NEXT_WEEK%":util.startOfNextWeek(startDate),
	"%START_WEEK%":util.toDateStr(util.startOfWeek(startDate),True),
	"%END_WEEK%":util.toDateStr(util.endOfWeek(startDate),True),
	"%M%": curTab(0),
	"%T%": curTab(1),
	"%W%": curTab(2),
	"%R%": curTab(3),
	"%F%": curTab(4),
	"%S%": curTab(5),
	}
	
	#build the calendar
	for i,day in enumerate(schedule):
		
		calendar += buildDay(locations, roles, day, util.addDays(startDate, i))
		
	#add the body of the page
	params["%CAL_BODY%"] = calendar
		
	return view.render("ui/webCal.html", params, tab=tab)
Example #3
0
def display(date, tab):
	"""
	Displays the calendar page
	"""
	standardSlots = ["08:00AM", "08:15AM", "08:30AM", "08:45AM", "09:00AM", "09:15AM",
			"09:30AM", "09:45AM", "10:00AM", "10:15AM", "10:30AM", "10:45AM", "11:00AM",
			"11:15AM", "11:30AM", "11:45AM", "12:00PM", "12:15PM", "12:30PM", "12:45PM",
			"01:00PM", "01:15PM", "01:30PM", "01:45PM", "02:00PM", "02:15PM", "02:30PM",
			"02:45PM", "03:00PM", "03:15PM", "03:30PM", "03:45PM", "04:00PM", "04:15PM",
			"04:30PM", "04:45PM", "05:00PM", "05:15PM", "05:30PM", "05:45PM", "06:00PM",
			"06:15PM", "06:30PM", "06:45PM", "07:00PM"]
	
	schedule = [] #list of dicts of lists, days -> timeslot -> appointment list
	locations = None
	roles = None

	for day in range(util.DAYS_IN_WEEK):
		schedule.append({})
	
	#the beginning of the week - the week is either given or the current week is used
	startDate = util.startOfWeek(util.toDatetime(date) if date else util.today())
	tab = int(tab)
	
	#build a list of maps of time to appointments with some default values
	#prepopulated so they are always displayed
	for day in schedule:
	
		for timeslot in standardSlots:
		
			day[timeslot] = []
	
	#get a database connection
	conn = services.getConnection()
	
	#get all the locations and roles
	locations = services.getLocations(conn)
	roles = sorted(services.getRoles(conn))
	
	#get all the appointments for the week and add them to the schedule
	for appointment in services.getAppointments(conn, startDate):
		
		time = appointment.getFTime()
		weekday = appointment.time.weekday()
		
		#if the appointment is not scheduled for one of the standard times
		#then add that time slot
		if time not in schedule[weekday]:
			
			schedule[weekday][time] = []

		schedule[weekday][time].append(appointment)
			
	conn.close()
	
	#format and return the page
	return build(locations, roles, schedule, startDate, tab)
Example #4
0
def run():
	
	#YYYY-MM-DD HH:MM:SS
	
	#--------------------------SETUP------------------------------------------
	conn = services.getConnection()
	staff = [ model.staff.StaffMember("test1", 1, False), model.staff.StaffMember("test2", 1, True), model.staff.StaffMember("test3", 2, True) ]
	apps = [ model.appointment.Appointment("2010-12-25 11:00:00", "test1", "Albany"),
			model.appointment.Appointment("2010-12-23 00:00:00", "test1", "Corvallis"),
			model.appointment.Appointment("2010-12-21 00:00:00", "test2", "Albany"),
			model.appointment.Appointment(util.toDatetime("2010-12-25 00:00:00"), "test3", "Albany"),
			model.appointment.Appointment("2010-12-24 00:00:00", "test3", "Corvallis"),
			model.appointment.Appointment("2010-11-24 00:00:00", "test3", "Corvallis") ]
	
	objs = []

	for a in apps:
		services.deleteAppointment(conn, a.time, a.staffName)
		
	for s in staff:
		services.deleteStaff(conn, s.name)

	for s in staff:
		objs.append(s)
	
	for a in apps:
		objs.append(a)
		
	for o in objs:
		o.flush(conn)
	
	#-----------------------------ALL STAFF-----------------------------------

	#all staff
	results = filterList( services.getAllStaff(conn), staff )
	print "all staff", len(results) == 3
	
	#only role 1
	results = filterList( services.getAllStaff(conn, roleId = 1), staff )
	print "role 1 staff", len(results) == 2
		
	#only active
	results = filterList( services.getAllStaff(conn, active=True), staff )
	print "active staff", len(results) == 2
	
	#only inactive, role 1
	results = filterList( services.getAllStaff(conn, active=False, roleId = 1), staff )
	print "inactive, role 1 staff", len(results) == 1
	

	#------------------------------ALL APPOINTMENTS---------------------------
	
	#all appointments
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00"))), apps )
	print "all appointments", len(results) == 5
	
	#only role 1
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), roleId = 1), apps )
	print "role 1 appointments", len(results) == 3
	
	#only Albany
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), location = "Albany"), apps )
	print "Albany appointments", len(results) == 3

	#only Corvallis role 2
	results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), location = "Corvallis", roleId = 2), apps )
	print "role 2 corvallis appointments", len(results) == 1
	
	#---------------------------------ROLES-------------------------------------
	print "3 Roles found", len( services.getRoles(conn) ) == 3
	
	#---------------------------CLEAN UP--------------------------------------
	for a in apps:
		services.deleteAppointment(conn, a.time, a.staffName)
		
	for s in staff:
		services.deleteStaff(conn, s.name)