Пример #1
0
func SaveBlog(ctx *middleware.Context, blog model.Blog) {
	if blog.Title == "" || blog.Content == "" {
		ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.save.failed"))
	} else {
		tags := ctx.R.PostForm["tags"]
		blog.SetTags(tags)
		signedUser := ctx.S.Get("SignedUser").(model.User)
		blog.UpdateUser = signedUser.Username
		if blog.Version == 0 {
			blog.State = "DRAFT"
			blog.Priority = 5
			blog.Author = signedUser
			blog.CreateUser = signedUser.Username
			err := blog.Insert()
			PanicIf(err)
		} else {
			err := blog.Update()
			PanicIf(err)
		}
		dbBlog, err := blog.GetBlogById()
		PanicIf(err)
		ctx.Set("Blog", dbBlog)

		ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.save.success"))
	}

	tags, err := blog.GetAllTags()
	PanicIf(err)
	ctx.Set("Tags", tags)

	ctx.HTML(200, "blog/edit", ctx)
}