Ejemplo n.º 1
0
func Edit(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
	c := appengine.NewContext(req)
	var t testimonials.Testimonial

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

	if t.ID > 0 {
		if err := t.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["Testimonial"] = t
	bag["ActiveNav"] = "testimonials"
	r.HTML(200, "admin/testimonials/edit", bag)

	return
}
Ejemplo n.º 2
0
func Get(rw http.ResponseWriter, req *http.Request, r render.Render, params martini.Params) {
	var t testimonials.Testimonial
	ctx := appengine.NewContext(req)

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

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

	r.JSON(200, t)
}