示例#1
0
文件: post.go 项目: Raysmond/RaysGo
// View a post
func (this *PostController) View() {
	id, _ := helpers.Str2Int64(this.GetParam(":id"))

	var node *models.Node
	if node = models.GetNode(id); node == nil {
		this.Abort("404")
	}

	node.UpdateCounter()

	if tags, err := models.GetNodeTags(node.IUser.Id, node.Id); err == nil {
		this.Data["Tags"] = *tags
	}

	if comments, err := models.GetNodeComments(id); err == nil {
		this.Data["Comments"] = comments
	}

	var form models.PostForm
	if err := this.ParseForm(&form); err == nil {
		this.Data["CommentForm"] = form
	}

	this.Data["Title"] = node.Title
	this.Data["Post"] = node
	this.Data["User"] = models.GetUser(node.IUser.Id)
	this.Data["CanEdit"] = this.canEditPost(node)
	this.TplNames = "post/view.html"
}
示例#2
0
文件: post.go 项目: Raysmond/RaysGo
// Edit a post
func (this *PostController) Edit() {
	id, _ := helpers.Str2Int64(this.GetParam(":id"))
	var post *models.Node
	if post = models.GetNode(id); post == nil {
		this.Abort("404")
	}
	if !this.canEditPost(post) {
		this.FlashError("Sorry, you don't have the permission to edit the post!")
		this.SaveFlash()
		this.RedirectPost(id)
	}

	form := models.PostForm{}
	form.SetData(post)

	tagStr := ""
	if tags, err := models.GetNodeTags(post.IUser.Id, post.Id); err == nil {
		comma := ""
		for _, tag := range *tags {
			tagStr = tagStr + comma + tag.Name
			comma = ", "
		}
		form.Tags = tagStr
	}

	this.Data["Title"] = "Edit - " + post.Title
	this.Data["Post"] = post
	this.Data["Form"] = form
	this.Data["TYPE_"+form.ContentType] = true
	this.Data["STATUS_"+form.Status] = true
	this.TplNames = "post/edit.html"

}