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


Golang models.Post类代码示例

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


在下文中一共展示了Post类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: EditPostSubmit

func (this *PostRouter) EditPostSubmit() {
	this.TplNames = "post/edit.html"

	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)
	post.ListTopics(&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(), 302)
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:28,代码来源:post.go

示例3: Valid

func (form *CommentAdminForm) Valid(v *validation.Validation) {
	user := models.User{Id: form.User}
	if user.Read() != nil {
		v.SetError("User", "admin.not_found_by_id")
	}

	post := models.Post{Id: form.Post}
	if post.Read() != nil {
		v.SetError("Post", "admin.not_found_by_id")
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:11,代码来源:form.go

示例4: NewPostSubmit

func (this *PostRouter) NewPostSubmit() {
	this.TplNames = "post/new.html"

	if this.CheckActiveRedirect() {
		return
	}

	form := post.PostForm{Locale: this.Locale}
	topicSlug := this.GetString("topic")
	if len(topicSlug) > 0 {
		topic := models.Topic{Slug: topicSlug}
		err := topic.Read("Slug")
		if err == nil {
			form.Category = topic.Category.Id
			form.Topic = topic.Id
			this.Data["Topic"] = &topic
		} else {
			beego.Error("Can not find topic by slug:", topicSlug)
		}
	} else {
		topicId, err := this.GetInt("Topic")
		if err == nil {
			topic := models.Topic{Id: int(topicId)}
			err = topic.Read("Id")
			if err == nil {
				form.Category = topic.Category.Id
				form.Topic = topic.Id
				this.Data["Topic"] = &topic
			} else {
				beego.Error("Can not find topic by id:", topicId)
			}
		} else {
			beego.Error("Parse param Topic from request failed", err)
		}
	}
	if categorySlug := this.GetString("category"); categorySlug != "" {
		beego.Debug("Find category slug:", categorySlug)
		category := models.Category{Slug: categorySlug}
		category.Read("Slug")
		this.Data["Category"] = &category
	}
	post.ListTopics(&form.Topics)
	if !this.ValidFormSets(&form) {
		return
	}

	var post models.Post
	if err := form.SavePost(&post, &this.User); err == nil {
		this.JsStorage("deleteKey", "post/new")
		this.Redirect(post.Link(), 302)
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:52,代码来源:post.go

示例5: 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

示例6: Save

// view for new object save
func (this *PostAdminRouter) Save() {
	form := this.GetForm(true)
	if !this.ValidFormSets(&form) {
		return
	}

	var post models.Post
	form.SetToPost(&post)
	if err := post.Insert(); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/post/%d", post.Id), 302, "CreateSuccess")
		return
	} else {
		beego.Error(err)
		this.Data["Error"] = err
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:17,代码来源:admin_post.go

示例7: loadComments

func (this *PostRouter) loadComments(post *models.Post, comments *[]*models.Comment) {
	qs := post.Comments()
	if num, err := qs.RelatedSel("User").OrderBy("Id").All(comments); err == nil {
		this.Data["Comments"] = *comments
		this.Data["CommentsNum"] = num
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:7,代码来源:post.go

示例8: SavePost

func (form *PostForm) SavePost(post *models.Post, user *models.User) error {
	utils.SetFormValues(form, post)
	post.Category = &models.Category{Id: form.Category}
	post.Topic = &models.Topic{Id: form.Topic}
	post.User = user
	post.LastReply = user
	post.LastAuthor = user
	post.CanEdit = true
	post.ContentCache = utils.RenderMarkdown(form.Content)

	// mentioned follow users
	FilterMentions(user, post.ContentCache)

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

示例9: SetToPost

func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	if post.User == nil {
		post.User = &models.User{}
	}
	post.User.Id = form.User

	if post.LastReply == nil {
		post.LastReply = &models.User{}
	}
	post.LastReply.Id = form.LastReply

	if post.LastAuthor == nil {
		post.LastAuthor = &models.User{}
	}
	post.LastAuthor.Id = form.LastAuthor

	if post.Topic == nil {
		post.Topic = &models.Topic{}
	}
	post.Topic.Id = form.Topic
	//get category
	topic := &models.Topic{Id: form.Topic}
	if err := topic.Read("Id"); err == nil {
		if post.Category == nil {
			post.Category = &models.Category{}
		}
		post.Category.Id = topic.Category.Id
	}
	post.ContentCache = utils.RenderMarkdown(post.Content)
}
开发者ID:varding,项目名称:wetalk,代码行数:32,代码来源:form.go

示例10: SinglePostCommentSubmit

//New Comment
func (this *PostRouter) SinglePostCommentSubmit() {
	this.TplNames = "post/post.html"

	if this.CheckActiveRedirect() {
		return
	}

	var postMd models.Post
	if this.loadPost(&postMd, nil) {
		return
	}

	var redir bool

	defer func() {
		if !redir {
			var comments []*models.Comment
			this.loadComments(&postMd, &comments)
		}
	}()

	form := post.CommentForm{}
	if !this.ValidFormSets(&form) {
		return
	}

	comment := models.Comment{}
	if err := form.SaveComment(&comment, &this.User, &postMd); err == nil {
		post.FilterCommentMentions(&this.User, &postMd, &comment)
		this.JsStorage("deleteKey", "post/comment")
		this.Redirect(postMd.Link(), 302)
		redir = true

		post.PostReplysCount(&postMd)
	}
}
开发者ID:varding,项目名称:wetalk,代码行数:37,代码来源:post.go

示例11: 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

示例12: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。