本文整理汇总了Golang中github.com/go-tango/wego/models.Post类的典型用法代码示例。如果您正苦于以下问题:Golang Post类的具体用法?Golang Post怎么用?Golang Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Post
func (this *PostRouter) Post() {
if this.CheckActiveRedirect() {
return
}
var postMd models.Post
if this.loadPost(&postMd, &this.User) {
return
}
if !postMd.CanEdit {
this.FlashRedirect(postMd.Path(), 302, "CanNotEditPost")
}
form := post.PostForm{}
form.SetFromPost(&postMd)
models.FindTopics(&form.Topics)
if !this.ValidFormSets(&form) {
return
}
if err := form.UpdatePost(&postMd, &this.User); err == nil {
this.JsStorage("deleteKey", "post/edit")
this.Redirect(postMd.Link())
return
}
this.Render("post/edit.html", this.Data)
}
示例2: UpdatePost
func (form *PostForm) UpdatePost(post *models.Post, user *models.User) error {
changes := utils.FormChanges(post, form)
if len(changes) == 0 {
return nil
}
utils.SetFormValues(form, post)
post.CategoryId = form.Category
post.TopicId = form.Topic
for _, c := range changes {
if c == "Content" {
post.ContentCache = utils.RenderMarkdown(form.Content)
changes = append(changes, "ContentCache")
}
}
// update last edit author
if post.LastAuthorId != user.Id {
post.LastAuthorId = user.Id
changes = append(changes, "LastAuthor")
}
changes = append(changes, "Updated")
return models.UpdateById(post.Id, post, models.Obj2Table(changes)...)
}
示例3: PostReplysCount
func PostReplysCount(post *models.Post) {
cnt, err := models.CountCommentsByPostId(post.Id)
if err == nil {
post.Replys = int(cnt)
//disable post editable
post.CanEdit = false
err = models.UpdateById(post.Id, post, "replys", "can_edit")
}
if err != nil {
log.Error("PostReplysCount ", err)
}
}
示例4: SavePost
func (form *PostForm) SavePost(post *models.Post, user *models.User) error {
utils.SetFormValues(form, post)
post.CategoryId = form.Category
post.TopicId = form.Topic
post.UserId = user.Id
post.LastReplyId = user.Id
post.LastAuthorId = user.Id
post.CanEdit = true
post.ContentCache = utils.RenderMarkdown(form.Content)
// mentioned follow users
FilterMentions(user, post.ContentCache)
return post.Insert()
}
示例5: Get
func (this *EditPost) Get() {
if this.CheckActiveRedirect() {
return
}
var postMd models.Post
if this.loadPost(&postMd, &this.User) {
return
}
if !postMd.CanEdit {
this.Redirect(postMd.Link())
return
}
form := post.PostForm{}
form.SetFromPost(&postMd)
models.FindTopics(&form.Topics)
this.SetFormSets(&form)
this.Render("post/edit.html", this.Data)
}
示例6: SaveComment
func (form *CommentForm) SaveComment(comment *models.Comment, user *models.User, post *models.Post) error {
comment.Message = form.Message
comment.MessageCache = utils.RenderMarkdown(form.Message)
comment.UserId = user.Id
comment.PostId = post.Id
if err := models.InsertComment(comment); err == nil {
post.LastReplyId = user.Id
models.UpdateById(post.Id, post, "last_reply_id", "last_replied")
cnt, _ := models.CountCommentsLTEId(comment.Id)
comment.Floor = int(cnt)
return models.UpdateById(comment.Id, comment, "floor")
} else {
return err
}
}
示例7: SetToPost
func (form *PostAdminForm) SetToPost(post *models.Post) {
utils.SetFormValues(form, post)
post.UserId = form.User
post.LastReplyId = form.LastReply
post.LastAuthorId = form.LastAuthor
post.TopicId = form.Topic
//get category
if topic, err := models.GetTopicById(form.Topic); err == nil {
post.CategoryId = topic.CategoryId
}
post.ContentCache = utils.RenderMarkdown(post.Content)
}