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