Пример #1
0
//Upload renders the new presentation upload page.
func Upload(c util.Context) (err error) {
	uploadURL, err := blobstore.UploadURL(c, "/admin/presentation/upload", nil)
	if err != nil {
		return
	}

	acts, err := activation.GetAfterTime(time.Now(), c)
	if err != nil {
		return
	}

	type actWithName struct {
		A *activation.Activation
		P *presentation.Presentation
	}

	ans := make([]actWithName, len(acts))

	for i, a := range acts {
		pk := a.Presentation
		var p *presentation.Presentation
		p, err = presentation.GetByKey(pk, c)
		if err != nil {
			c.Errorf("Could not load presentation: %v", err)
			continue
		}
		ans[i] = actWithName{a, p}
	}

	util.RenderLayout("upload.html", "Nahrať prezentáciu", struct {
		UploadURL *url.URL
		Ans       []actWithName
	}{uploadURL, ans}, c)
	return
}
Пример #2
0
//Presentation handles showing page with details about a presentation.
func Presentation(c util.Context) (err error) {
	pk, err := datastore.DecodeKey(c.Vars["id"])
	if err != nil {
		return
	}

	p, err := presentation.GetByKey(pk, c)
	if err != nil {
		return
	}
	as, err := action.GetFor(p, c)
	if err != nil {
		return
	}

	a := prepareActions(as)

	desc := blackfriday.MarkdownCommon(p.Description)

	acts, err := activation.GetForPresentation(pk, c)
	if err != nil {
		return
	}

	util.RenderLayout("presentation.html", "Info o prezentácií", struct {
		P           *presentation.Presentation
		A           map[string][]time.Time
		Desc        template.HTML
		ZeroTime    time.Time
		Domain      string
		Activations []*activation.Activation
		Tz          *time.Location
	}{p, a, template.HTML(desc), time.Date(0001, 01, 01, 00, 00, 00, 00, utc), appengine.DefaultVersionHostname(c), acts, util.Tz}, c, "/static/js/underscore-min.js", "/static/js/presentation.js")
	return
}
Пример #3
0
func ActivateScheduled(c util.Context) (err error) {
	t := time.Now()
	as, err := activation.GetBeforeTime(t, c)
	if err != nil {
		return
	}

	for _, a := range as {
		var p *presentation.Presentation
		p, err = presentation.GetByKey(a.Presentation, c)
		if err != nil {
			c.Errorf("Couldn't load presentation %s", a.Presentation.Encode())
			continue
		}

		if a.Op == activation.Activate {
			p.Active = true
		} else {
			p.Active = false
		}

		err = p.Save(c)
		if err != nil {
			c.Errorf("Couldn't save presentation: %v", p.Name)
			continue
		}

		err = a.Delete(c)
		if err != nil {
			c.Errorf("Couldn't remove activation: %s", a.Key)
			continue
		}
	}
	return
}
Пример #4
0
func getPresentation(c util.Context) (p *presentation.Presentation, err error) {
	key, err := datastore.DecodeKey(c.Vars["key"])
	if err != nil {
		return
	}

	p, err = presentation.GetByKey(key, c)
	return
}
Пример #5
0
//Activate handles activation of presentation.
func Activate(c util.Context) (err error) {
	key, err := datastore.DecodeKey(c.R.FormValue("id"))
	if err != nil {
		return
	}

	p, err := presentation.GetByKey(key, c)
	if err != nil {
		return
	}
	p.Active = true
	p.Save(c)
	http.Redirect(c.W, c.R, c.R.Referer(), 303)
	return
}
Пример #6
0
//Delete handles deleting of presentation.
func Delete(c util.Context) (err error) {
	key, err := datastore.DecodeKey(c.R.FormValue("id"))
	if err != nil {
		return
	}

	p, err := presentation.GetByKey(key, c)
	if err != nil {
		return
	}
	err = p.Delete(c)
	if err != nil {
		return
	}
	http.Redirect(c.W, c.R, c.R.Referer(), 303)
	return
}