Example #1
0
func (this *BulletinAdminRouter) Update() {
	form := bulletin.BulletinAdminForm{Id: this.object.Id}
	if this.ValidFormSets(&form) == false {
		return
	}

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

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

	// update changed fields only
	if len(changes) > 0 {
		form.SetToBulletin(&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)
	}
}
Example #2
0
func (this *BulletinAdminRouter) Save() {
	form := bulletin.BulletinAdminForm{Create: true}
	if this.ValidFormSets(&form) == false {
		return
	}

	var bulletin models.Bulletin
	form.SetToBulletin(&bulletin)
	if err := bulletin.Insert(); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/bulletin/%d", bulletin.Id), 302, "CreateSuccess")
		return
	} else {
		beego.Error(err)
		this.Data["Error"] = err
	}
}
Example #3
0
func (this *BulletinAdminRouter) Edit() {
	form := bulletin.BulletinAdminForm{}
	form.SetFromBulletin(&this.object)
	this.SetFormSets(&form)
}