def getRenderedOuting(outing): """ Renders and returns an outing in html. outing: the outing whose html to generate returns: string """ return jtr.getRenderedTemplate(pathToOutingTemplates, outingTemplateName, { 'outing': outing })
def getOutingButtonsTop(handler): """ Renders and returns the buttons for the top of an outings page. handler: the current page handler returns: string """ # Determine if the user can add an outing loggedInUser = uau.getLoggedInUser(handler) canAddOuting = False if loggedInUser != None and uau.doesUserHavePermission(loggedInUser.accountLevel, uau.poster): canAddOuting = True # Get the rendered buttons return jtr.getRenderedTemplate(pathToOutingTemplates, buttonsTopTemplateName, { 'can_add_outing': canAddOuting })
def getRenderedOutingsContainer(outings, showShowcase = True, showUpcoming = True, showPast = True): """ Renders and returns the outings container with the given outings. outings: the list of outings whose html to generate showShowcase: whether to show the showcase outings showUpcoming: whether to show the upcoming outings showPast: whether to show the past outings returns: string """ # Showcase Outings showcaseOutings = [] for outing in outings: if outing.showcase: showcaseOutings.append(outing) showcaseOutings.sort(key=lambda o: o.departureTime, reverse=True) showcaseHtml = getRenderedOutings(showcaseOutings) # Upcoming and Past Outings upcomingOutings = [] pastOutings = [] for outing in outings: if outing.departureTime > datetime.datetime.now(): upcomingOutings.append(outing) else: pastOutings.append(outing) upcomingOutings.sort(key=lambda o: o.departureTime) pastOutings.sort(key=lambda o: o.departureTime, reverse=True) upcomingHtml = getRenderedOutings(upcomingOutings) pastHtml = getRenderedOutings(pastOutings) # Render the container templateValues = { 'show_past': showPast, 'show_showcase': showShowcase, 'show_upcoming': showUpcoming, 'past_outings': pastHtml, 'showcase_outings': showcaseHtml, 'upcoming_outings': upcomingHtml } return jtr.getRenderedTemplate(pathToOutingTemplates, outingsContainerTemplateName, templateValues)