Пример #1
0
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)
}
Пример #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
	}
}