Ejemplo n.º 1
0
// view for update object
func (this *TopicAdminRouter) Update() {
	form := post.TopicAdminForm{Id: this.object.Id}
	if this.ValidFormSets(&form) == false {
		return
	}

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

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

	// update changed fields only
	if len(changes) > 0 {
		form.SetToTopic(&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)
	}
}
Ejemplo n.º 2
0
// view for new object save
func (this *TopicAdminRouter) Save() {
	form := post.TopicAdminForm{Create: true}
	if this.ValidFormSets(&form) == false {
		return
	}

	var topic models.Topic
	form.SetToTopic(&topic)
	if err := topic.Insert(); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/topic/%d", topic.Id), 302, "CreateSuccess")
		return
	} else {
		beego.Error(err)
		this.Data["Error"] = err
	}
}
Ejemplo n.º 3
0
// view for edit object
func (this *TopicAdminRouter) Edit() {
	form := post.TopicAdminForm{}
	form.SetFromTopic(&this.object)
	this.SetFormSets(&form)
}