Ejemplo n.º 1
0
// view for update object
func (this *PageAdminEdit) Post() {
	form := page.PageAdminForm{}
	if this.ValidFormSets(&form) == false {
		return
	}

	// get changed field names
	changes := utils.FormChanges(&this.object, &form)

	url := fmt.Sprintf("/admin/page/%d", this.object.Id)

	// update changed fields only
	if len(changes) > 0 {
		form.SetToPage(&this.object)
		if err := models.UpdateById(this.object.Id, this.object, models.Obj2Table(changes)...); err == nil {
			this.FlashRedirect(url, 302, "UpdateSuccess")
			return
		} else {
			log.Error(err)
			this.Data["Error"] = err
		}
	} else {
		this.Redirect(url, 302)
	}
}
Ejemplo n.º 2
0
// view for new object save
func (this *PageAdminNew) Post() {
	form := page.PageAdminForm{Create: true}
	if !this.ValidFormSets(&form) {
		return
	}

	var a models.Page
	form.SetToPage(&a)
	if err := models.Insert(&a); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/page/%d", a.Id), 302, "CreateSuccess")
		return
	} else {
		log.Error(err)
		this.Data["Error"] = err
	}
}