示例#1
0
// view for update object
func (this *CommentAdminEdit) Post() {
	form := post.CommentAdminForm{}
	if this.ValidFormSets(&form) == false {
		return
	}

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

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

	// update changed fields only
	if len(changes) > 0 {
		form.SetToComment(&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)
	}
}
示例#2
0
// view for new object save
func (this *CommentAdminNew) Post() {
	form := post.CommentAdminForm{Create: true}
	if this.ValidFormSets(&form) == false {
		return
	}

	var comment models.Comment
	form.SetToComment(&comment)
	if err := models.Insert(&comment); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/comment/%d", comment.Id), 302, "CreateSuccess")
		return
	} else {
		log.Error(err)
		this.Data["Error"] = err
	}
}
示例#3
0
// view for edit object
func (this *CommentAdminEdit) Get() {
	form := post.CommentAdminForm{}
	form.SetFromComment(&this.object)
	this.SetFormSets(&form)
}