// view for update object func (this *UserAdminRouter) Update() { form := auth.UserAdminForm{Id: this.object.Id} if this.ValidFormSets(&form) == false { return } // get changed field names changes := utils.FormChanges(&this.object, &form) url := fmt.Sprintf("/admin/user/%d", this.object.Id) // update changed fields only if len(changes) > 0 { form.SetToUser(&this.object) if err := this.object.Update(changes...); err == nil { this.FlashRedirect(url, 302, "UpdateSuccess") return } else { beego.Error(err) this.Data["Error"] = err } } else { this.Redirect(url, 302) } }
// view for new object save func (this *UserAdminRouter) Save() { form := auth.UserAdminForm{Create: true} if this.ValidFormSets(&form) == false { return } var user models.User form.SetToUser(&user) if err := user.Insert(); err == nil { this.FlashRedirect(fmt.Sprintf("/admin/user/%d", user.Id), 302, "CreateSuccess") return } else { beego.Error(err) this.Data["Error"] = err } }
// view for edit object func (this *UserAdminRouter) Edit() { form := auth.UserAdminForm{} form.SetFromUser(&this.object) this.SetFormSets(&form) }