func session(w http.ResponseWriter, r *http.Request) *webapp.Error { idString := r.FormValue("id") if idString == "" { return missingFields(w) } id, err := strconv.ParseInt(idString, 10, 64) if err != nil { return invalidData(w, fmt.Sprintf("Couldn't parse %q as ID", idString)) } c := appengine.NewContext(r) session, err := classes.SessionWithID(c, id) switch err { case nil: break case classes.ErrSessionNotFound: return invalidData(w, fmt.Sprintf("No such session")) default: return webapp.InternalError(fmt.Errorf("failed to find session %d: %s", id, err)) } classList := session.Classes(c) sort.Sort(classes.ClassesByStartTime(classList)) teachers := classes.TeachersByClass(c, classList) data := map[string]interface{}{ "Session": session, "Classes": classes.GroupedByDay(classList), "DaysInOrder": daysInOrder, "Teachers": teachers, } if err := sessionPage.Execute(w, data); err != nil { return webapp.InternalError(err) } return nil }
func index(w http.ResponseWriter, r *http.Request) *webapp.Error { c := appengine.NewContext(r) announcements := staff.CurrentAnnouncements(c, time.Now()) sort.Sort(staff.AnnouncementsByExpiration(announcements)) sessions := classes.Sessions(c, time.Now()) schedules := []sessionSchedule{} for _, session := range sessions { sessionClasses := session.Classes(c) if len(sessionClasses) == 0 { continue } sched := sessionSchedule{ Session: session, ClassesByDay: classes.GroupedByDay(sessionClasses), TeachersByClass: classes.TeachersByClass(c, sessionClasses), } schedules = append(schedules, sched) } classesBySession := make(map[int64][]*classes.Class) for _, session := range sessions { classesBySession[session.ID] = session.Classes(c) } yins := yogassage.Classes(c, dateOnly(time.Now())) sort.Sort(yogassage.ByDate(yins)) data := map[string]interface{}{ "Announcements": announcements, "Schedules": schedules, "DaysInOrder": daysInOrder, "YinYogassage": yins, } if u := user.Current(c); u != nil { acct, err := maybeOldAccount(c, u) switch err { case nil: break case account.ErrUserNotFound: http.Redirect(w, r, "/login/new", http.StatusSeeOther) return nil default: return webapp.InternalError(fmt.Errorf("failed to find user: %s", err)) } data["LoggedIn"] = true data["User"] = acct if url, err := user.LogoutURL(c, "/"); err != nil { return webapp.InternalError(fmt.Errorf("Error creating logout url: %s", err)) } else { data["LogoutURL"] = url } switch staffer, err := maybeOldStaff(c, acct, u); err { case nil: data["Staff"] = staffer case staff.ErrUserIsNotStaff: break default: return webapp.InternalError(err) } data["Admin"] = user.IsAdmin(c) regs := registrationsForUser(c, acct.ID) if len(regs) == 0 { regs = registrationsForUser(c, u.ID) } data["Registrations"] = regs } if err := indexPage.Execute(w, data); err != nil { return webapp.InternalError(err) } return nil }