func (this *BulletinAdminEdit) Post() { form := bulletin.BulletinAdminForm{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/bulletin/%d", this.object.Id) // update changed fields only if len(changes) > 0 { form.SetToBulletin(&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) } }
func (this *BulletinAdminNew) Post() { form := bulletin.BulletinAdminForm{Create: true} if this.ValidFormSets(&form) == false { return } var bulletin models.Bulletin form.SetToBulletin(&bulletin) if err := models.Insert(&bulletin); err == nil { this.FlashRedirect(fmt.Sprintf("/admin/bulletin/%d", bulletin.Id), 302, "CreateSuccess") return } else { log.Error(err) this.Data["Error"] = err } }
func (this *BulletinAdminEdit) Get() { form := bulletin.BulletinAdminForm{} form.SetFromBulletin(&this.object) this.SetFormSets(&form) }