示例#1
0
func Edit(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
	c := appengine.NewContext(req)
	var eq equipment.Equipment

	intID, err := strconv.Atoi(params["id"])
	if err == nil {
		eq.ID = int64(intID)
	}

	if eq.ID > 0 {
		if err := eq.Get(c); err != nil {
			http.Redirect(rw, req, "/admin?error="+err.Error(), http.StatusFound)
			return
		}
	}

	bag := make(map[string]interface{}, 0)
	bag["Host"] = req.URL.Host
	bag["Admin"] = true
	bag["Equipment"] = eq
	bag["ActiveNav"] = "equipment"
	r.HTML(200, "admin/equipment/edit", bag)

	return
}
示例#2
0
func Get(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
	var e equipment.Equipment
	ctx := appengine.NewContext(req)

	intID, err := strconv.Atoi(params["id"])
	if err == nil {
		e.ID = int64(intID)
	}

	err = e.Get(ctx)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}

	r.JSON(200, e)
}