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"
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)