示例#1
0
文件: webCal.py 项目: jworr/scheduler
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)
示例#2
0
文件: webCal.py 项目: jworr/scheduler
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"
示例#3
0
文件: view.py 项目: jworr/scheduler
def render(templateFile, params, datePickerStartDate=None, tab=None):
	"""
	Reads the html with embeded replacement tokens and applies the params
	"""
	#open and read the file
	theFile = open(templateFile, "r")
	template = theFile.read()
	theFile.close()
	
	#find all the replacement tags that are used in the template file
	allTags = findTags(template)
	
	#replace all the parameters
	for param, value in params.items():
		
		replacement = ""
		
		if type(value) == datetime.datetime:
			replacement = util.toDateStr(value)
		elif value != None:
			replacement = str(value)
		
		#replace the parameter with the given value
		template = template.replace(param, replacement)
		
		#keep track of all the replacement tags that weren't used
		if param in allTags:
			allTags.remove(param)
	
	#for all the remaining tags fill them in with a blank space
	for tag in allTags:
		template = template.replace(tag, "")
		
	return header(datePickerStartDate, tab) + template + footer()
示例#4
0
def getAppointments(connection, startDate, location=None, roleId=None):
	"""
	Returns all the appointments for the week starting with the given day
	connection - the database connection
	startDate - the first day of the week to get the appointments for
	location - optional, if given only the appointments for this location are retreived
	roleId - optional, the roleID of the staff member who has the appointment
	"""
	results = []
	cursor = connection.cursor()
	cursor.arraysize = 50
	
	query = "select " + model.commaSep(model.appointment.AppointmentColumns) \
	+ " from appointment, employee where employee_name = name " \
	+ "and time > %(start)s and time < %(end)s"

	#assemble a list of optional parameters
	ptriples = [ ("location", location, "site = %(location)s"), \
	("role", roleId, "role_id = %(role)i") ]

	params, clause = fullClause(ptriples, False)

	params["start"] = util.toDateStr(startDate)
	params["end"] = util.toDateStr(util.endOfWeek(startDate))
	query += clause
	
	cursor.execute(query, params)
	
	#store the results in appointment objects
	for row in cursor.fetchall():
	
		results.append( model.appointment.Appointment( *trimAll(row) ) )
		
	cursor.close()
	
	return results
示例#5
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
示例#6
0
文件: webCal.py 项目: jworr/scheduler
def buildSlot(locations, roles, apps, theDate, hourStamp, highlight):
	"""
	builds the HTML to represent a timeslot, i.e. a row in the calendar
	locations - a list of all the locations (strings)
	roles - a list of all the roles (role objects)
	apps - a list of all the appointments for the hour (appoinment objects)
	theDate - a date object representing the given day
	hourStamp - a formatted string representing the hour to build the html for
	highlight - a boolean for if the row should be 
	"""
	result = "<tr %s><td>%s</td>" % (ROW_COLOR_TAG2 if highlight else "", hourStamp)
	
	#for each location
	for i, loc in enumerate(locations):

		#pick the color of the row if the row is to be highlighted 
		colorTag = (ROW_COLOR_TAG if i % 2 else ROW_COLOR_TAG2) if highlight else ""

		#for each role
		for role in roles:

			#find all the appointments for the current location/site
			relevant = filter(lambda a: a.location == loc and a.getAppType() == role.roleId, apps)
			
			#build html for each appointment
			if len(relevant):
				result += "<td %s>" % colorTag

				for app in relevant:
					result += APP_TEMPLATE % ("class=\"booked\"" if app.isBooked() else "", \
					app.staffName, app.time, app.getAppType(), app.staffName)
				
				result += "</td>"
				
			#else build a placeholder
			else:
				result += NO_APP_TEMPLATE % (colorTag, role.roleId, loc, util.toDatetime(util.toDateStr(theDate),hourStamp))
				
	return result + "</tr>"
示例#7
0
def build( appointmentList, startOfWeek, location ):
	"""
	Formats and returns the html for the detailed list
	appointmentList - a list of days, each day is a list of appointments for that day
	startOfWeek - a datetime object that represents the start of the week
	location - the location to list the appointments for
	"""

	DAY_TEMPLATE = "<li class=\"important\">%s %s</li>\n"
	APP_TEMPLATE = "<li><a %s href=\"editAppointment?name=%s&time=%s\">%s %s %s</a></li>\n"
	EMPTY_TEMPLATE = "<li><a href=\"editAppointment?time=%s\">No Appointments</a></li>\n"

	appList = ""
	params = {"%LOCATION%":location}

	#display the appointments for each day
	for i,dayList in enumerate(appointmentList):
	
		datetime = util.addDays(startOfWeek, i)
		
		#generate the header for the day
		appList += DAY_TEMPLATE % ( util.toDayName(datetime), util.toDateStr(datetime, True) )
		
		#if there are any appointments for the day then show them
		if len(dayList):
		
			#generate the html for each appointment
			for app in sorted(dayList, timeCompare):
				appList += APP_TEMPLATE % ("class=\"booked\"" if app.isBooked() else "", app.staffName, app.time, app.getFTime(), app.staffName, "- " + app.description if app.description else "")
		
		#else show a place holder
		else:
			appList += EMPTY_TEMPLATE % datetime
	
	#add the scheduled appointments to the page
	params["%THE_LIST%"] = appList
		
	return view.render("ui/daydetails.html", params)
示例#8
0
	def getFDate(self):
		"""
		Returns the formatted date as a string in the format MM/DD/YYYY
		"""
		return util.toDateStr(self.time)