func (form *ArticleAdminForm) SetToArticle(article *models.Article) { utils.SetFormValues(form, article) if article.User == nil { article.User = &models.User{} } article.User.Id = form.User if article.LastAuthor == nil { article.LastAuthor = &models.User{} } article.LastAuthor.Id = form.LastAuthor article.ContentCache = utils.RenderMarkdown(article.Content) article.ContentCacheZhCn = utils.RenderMarkdown(article.ContentZhCn) }
// 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 } }