Beispiel #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)
}
Beispiel #2
0
func PublishBlog(ctx *middleware.Context, blog model.Blog) {
	switch ctx.R.Method {
	case "POST":
		if blog.Title == "" || blog.Content == "" {
			ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.publish.failed"))
		} else {
			tags := ctx.R.PostForm["tags"]
			blog.SetTags(tags)
			signedUser := ctx.S.Get("SignedUser").(model.User)
			blog.State = "PUBLISHED"
			blog.PublishDate = time.Now()
			if blog.Version == 0 {
				blog.Priority = 5
				blog.Author = signedUser
				blog.CreateUser = signedUser.Username
				err := blog.Insert()
				PanicIf(err)
			} else {
				err := blog.Update()
				PanicIf(err)
			}
		}
		ctx.Redirect("/blog/view/" + IntString(blog.Id))
	default:
		tags, err := blog.GetAllTags()
		PanicIf(err)
		ctx.Set("Tags", tags)

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