Esempio n. 1
0
// Get a list of visualizations
func listVisualizations(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	q := datastore.NewQuery("visualization").Order("-Date")

	// Parse filter parameters
	r.ParseForm()
	fUser := r.Form["user"]
	if len(fUser) > 0 && fUser[0] == "me" {
		u := user.Current(c)
		if u == nil {
			common.Serve401(w)
			return
		}
		q = q.Ancestor(model.GetAccountKey(c, u))
	}

	// Get visualizations
	var e []model.Visualization
	keys, err := q.GetAll(c, &e)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}

	// Prepare output
	output := make([]map[string]interface{}, 0)
	for i := range keys {
		output = append(output, map[string]interface{}{"Key": keys[i], "Title": e[i].Title, "Date": e[i].Date})
	}

	common.WriteJson(c, w, output)
}
Esempio n. 2
0
// Create a new visualization
func newVisualization(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)

	if u == nil {
		common.Serve401(w)
		return
	}

	e := model.Visualization{"Untitled", time.Now(), nil}

	key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "visualization", model.GetAccountKey(c, u)), &e)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}

	common.WriteJson(c, w, map[string]*datastore.Key{"key": key})
}
Esempio n. 3
0
File: modules.go Progetto: hamax/avy
// Create a new module
func newModule(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)

	acc, err := model.GetAccount(c, u)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}
	if acc == nil {
		common.Serve401(w)
		return
	}

	// Parse form data
	devname := r.PostFormValue("devname")
	name := r.PostFormValue("name")

	// Set user developer name
	if acc.Devname == "" {
		if devname == "" {
			common.Serve404(w) // TODO: maybe 400 instead
			return
		}
		acc.Devname = devname
		err := model.SaveAccount(c, u, acc)
		if err != nil {
			common.ServeError(c, w, err)
			return
		}
	} else {
		devname = acc.Devname
	}

	e := model.Module{devname, name, time.Now(), nil}
	_, err = datastore.Put(c, datastore.NewKey(c, "module", name, 0, model.GetAccountKey(c, u)), &e)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}

	common.WriteJson(c, w, map[string]string{"Devname": devname, "Name": name})
}