Exemple #1
0
// view for update object
func (this *ArticleAdminRouter) Update() {
	form := article.ArticleAdminForm{}
	if this.ValidFormSets(&form) == false {
		return
	}

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

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

	// update changed fields only
	if len(changes) > 0 {
		form.SetToArticle(&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)
	}
}
Exemple #2
0
// view for new object save
func (this *ArticleAdminRouter) Save() {
	form := article.ArticleAdminForm{Create: true}
	if !this.ValidFormSets(&form) {
		return
	}

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