Esempio n. 1
0
func staffPortal(w http.ResponseWriter, r *http.Request) *webapp.Error {
	c := appengine.NewContext(r)
	teachers := classes.Teachers(c)
	sort.Sort(classes.TeachersByName(teachers))
	announcements := staff.CurrentAnnouncements(c, time.Now())
	sort.Sort(staff.AnnouncementsByExpiration(announcements))
	sessions := classes.Sessions(c, time.Now())
	sort.Sort(classes.SessionsByStartDate(sessions))
	yins := yogassage.Classes(c, time.Now())
	sort.Sort(yogassage.ByDate(yins))
	data := map[string]interface{}{
		"Teachers":            teachers,
		"Announcements":       announcements,
		"Sessions":            sessions,
		"YinYogassageClasses": yins,
	}
	if err := staffPage.Execute(w, data); err != nil {
		return webapp.InternalError(err)
	}
	return nil
}
Esempio n. 2
0
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
}