当前位置: 首页>>代码示例>>Golang>>正文


Golang Post.Update方法代码示例

本文整理汇总了Golang中github.com/varding/wetalk/modules/models.Post.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.Update方法的具体用法?Golang Post.Update怎么用?Golang Post.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/varding/wetalk/modules/models.Post的用法示例。


在下文中一共展示了Post.Update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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.Category.Id = form.Category
	post.Topic.Id = 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.LastAuthor != nil && post.LastAuthor.Id != user.Id {
		post.LastAuthor = user
		changes = append(changes, "LastAuthor")
	}

	changes = append(changes, "Updated")

	return post.Update(changes...)
}
开发者ID:varding,项目名称:wetalk,代码行数:25,代码来源:form.go

示例2: PostReplysCount

func PostReplysCount(post *models.Post) {
	cnt, err := post.Comments().Count()
	if err == nil {
		post.Replys = int(cnt)
		//disable post editable
		post.CanEdit = false
		err = post.Update("Replys", "CanEdit")
	}
	if err != nil {
		beego.Error("PostReplysCount ", err)
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:12,代码来源:util.go

示例3: 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.User = user
	comment.Post = post
	if err := comment.Insert(); err == nil {
		post.LastReply = user
		post.Update("LastReply", "LastReplied")

		cnt, _ := post.Comments().Filter("Id__lte", comment.Id).Count()
		comment.Floor = int(cnt)
		return comment.Update("Floor")
	} else {
		return err
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:16,代码来源:form.go

示例4: Post

func (this *ApiRouter) Post() {
	if this.CheckActiveRedirect() {
		return
	}

	if this.IsAjax() {
		result := map[string]interface{}{
			"success": false,
		}
		action := this.GetString("action")
		switch action {
		case "toggle-best":
			if !this.User.IsAdmin {
				result["success"] = false
			} else {
				if postId, err := this.GetInt("post"); err == nil {
					//set post best
					var post models.Post
					if err := orm.NewOrm().QueryTable("post").Filter("Id", postId).One(&post); err == nil {
						post.IsBest = !post.IsBest
						if post.Update("IsBest") == nil {
							result["success"] = true
						}
					}
				}
			}
		case "toggle-fav":
			if postId, err := this.GetInt("post"); err == nil {
				var post models.Post
				if err := orm.NewOrm().QueryTable("post").Filter("Id", postId).One(&post); err == nil {
					if post.Id != 0 {
						var favoritePost models.FavoritePost
						if this.User.FavoritePosts().Filter("Post__id", post.Id).One(&favoritePost); err == nil {
							if favoritePost.Id > 0 {
								//toogle IsFav
								favoritePost.IsFav = !favoritePost.IsFav
								if favoritePost.Update("IsFav") == nil {
									//update user fav post count
									if favoritePost.IsFav {
										this.User.FavPosts += 1
									} else {
										this.User.FavPosts -= 1

									}
									if this.User.Update("FavPosts") == nil {
										result["success"] = true
									}
								}
							} else {
								favoritePost = models.FavoritePost{
									User:  &this.User,
									Post:  &post,
									IsFav: true,
								}
								if favoritePost.Insert() == nil {
									//update user fav post count
									this.User.FavPosts += 1
									if this.User.Update("FavPosts") == nil {
										result["success"] = true
									}
								}
							}
						}
					}
				}
			}
		}
		this.Data["json"] = result
		this.ServeJson()
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:71,代码来源:post.go


注:本文中的github.com/varding/wetalk/modules/models.Post.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。