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)
	}
}
Beispiel #3
0
func EditBlog(ctx *middleware.Context, params martini.Params) {
	id := params["id"]
	blog := new(model.Blog)
	blog.Id = ParseInt(id)
	err := blog.GetBlog()
	PanicIf(err)
	ctx.Set("Blog", blog)

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

	ctx.HTML(200, "blog/edit", ctx)
}
Beispiel #4
0
func Blog(ctx *middleware.Context) {
	blog := new(model.Blog)
	blog.SetPageActive(true)
	blog.SetPageSize(10)
	pageNo := ParseInt(ctx.R.FormValue("page"))
	blog.SetPageNo(pageNo)
	blog.State = "PUBLISHED"
	blog.AddSortProperty("publish_date", "desc")
	blogList, total, err := blog.SearchByPage(true)
	PanicIf(err)

	blog.SetTotalRecord(total)
	blog.Result = blogList
	ctx.Set("Blog", blog)

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

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