Esempio n. 1
0
// view for update object
func (this *UserAdminEdit) Post() {
	form := auth.UserAdminForm{Id: int(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 := 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)
	}
}
Esempio n. 2
0
// view for new object save
func (this *UserAdminNew) Post() {
	form := auth.UserAdminForm{Create: true}
	if this.ValidFormSets(&form) == false {
		return
	}

	var user models.User
	form.SetToUser(&user)
	if err := models.Insert(&user); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/user/%d", user.Id), 302, "CreateSuccess")
		return
	} else {
		log.Error(err)
		this.Data["Error"] = err
	}
}
Esempio n. 3
0
// view for edit object
func (this *UserAdminEdit) Get() {
	form := auth.UserAdminForm{}
	form.SetFromUser(&this.object)
	this.SetFormSets(&form)
}