• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang models.Posts函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Category

// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Category() {
	this.TplName = "post/category.html"

	slug := this.GetString(":slug")
	cat := models.Category{Slug: slug}
	if err := cat.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}

	pers := 25

	qs := models.Posts().Filter("Category", &cat)
	qs = this.postsFilter(qs)

	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(pers, cnt)

	qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

	var posts []models.Post
	models.ListObjects(qs, &posts)

	this.Data["Posts"] = posts
	this.Data["Category"] = &cat
	this.Data["CategorySlug"] = cat.Slug
	this.Data["IsCategory"] = true

	var cats []models.Category
	this.setCategories(&cats)

	var topics []models.Topic
	this.setTopicsOfCat(&topics, &cat)
}
开发者ID:wildex,项目名称:wetalk,代码行数:35,代码来源:post.go


示例2: Category

//Get the posts by category
func (this *PostListRouter) Category() {
	this.TplNames = "post/home.html"

	//check category slug
	slug := this.GetString(":slug")
	cat := models.Category{Slug: slug}
	if err := cat.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}
	//get posts by category slug, order by Created desc
	qs := models.Posts().Filter("Category", &cat)
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	qs = qs.OrderBy("-LastReplied").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	var posts []models.Post
	models.ListObjects(qs, &posts)

	this.Data["Category"] = &cat
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	var topics []models.Topic
	this.setTopicsOfCategory(&topics, &cat)
	this.Data["CategorySlug"] = cat.Slug
	this.Data["SortSlug"] = ""
	var newBestPosts []models.Post
	this.setNewBestPostsOfCategory(&newBestPosts, &cat)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfCategory(&mostReplysPosts, &cat)
	this.setSidebarBuilletinInfo()
}
开发者ID:netxfly,项目名称:wetalk,代码行数:36,代码来源:post.go


示例3: Home

//Get the home page
func (this *PostListRouter) Home() {
	this.TplNames = "post/home.html"

	//get posts by Created datetime desc order
	var posts []models.Post
	qs := models.Posts()
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	qs = qs.OrderBy("-LastReplied").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()

	models.ListObjects(qs, &posts)
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	this.Data["SortSlug"] = ""
	this.Data["CategorySlug"] = "home"
	//new best posts
	var newBestPosts []models.Post
	this.setNewBestPosts(&newBestPosts)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPosts(&mostReplysPosts)
	this.setSidebarBuilletinInfo()
}
开发者ID:netxfly,项目名称:wetalk,代码行数:27,代码来源:post.go


示例4: List

// view for list model data
func (this *PostAdminRouter) List() {
	var posts []models.Post
	qs := models.Posts().RelatedSel()
	if err := this.SetObjects(qs, &posts); err != nil {
		this.Data["Error"] = err
		beego.Error(err)
	}
}
开发者ID:JessonChan,项目名称:wetalk,代码行数:9,代码来源:admin_post.go


示例5: Home

func (this *UserRouter) Home() {
	this.Data["IsUserHomePage"] = true
	this.TplNames = "user/home.html"

	var user models.User
	if this.getUser(&user) {
		return
	}

	//recent posts and comments
	limit := 5

	var posts []*models.Post
	var comments []*models.Comment

	user.RecentPosts().Limit(limit).RelatedSel().All(&posts)
	user.RecentComments().Limit(limit).RelatedSel().All(&comments)

	this.Data["TheUserPosts"] = posts
	this.Data["TheUserComments"] = comments

	//follow topics
	var ftopics []*models.FollowTopic
	var topics []*models.Topic
	ftNums, _ := models.FollowTopics().Filter("User", &user.Id).Limit(8).OrderBy("-Created").RelatedSel("Topic").All(&ftopics, "Topic")
	if ftNums > 0 {
		topics = make([]*models.Topic, 0, ftNums)
		for _, ft := range ftopics {
			topics = append(topics, ft.Topic)
		}
	}
	this.Data["TheUserFollowTopics"] = topics
	this.Data["TheUserFollowTopicsMore"] = ftNums >= 8

	//favorite posts
	var favPostIds orm.ParamsList
	var favPosts []models.Post
	favNums, _ := user.FavoritePosts().Limit(8).OrderBy("-Created").ValuesFlat(&favPostIds, "Post")
	if favNums > 0 {
		qs := models.Posts().Filter("Id__in", favPostIds)
		qs = qs.OrderBy("-Created").RelatedSel()
		models.ListObjects(qs, &favPosts)
	}
	this.Data["TheUserFavoritePosts"] = favPosts
	this.Data["TheUserFavoritePostsMore"] = favNums >= 8

}
开发者ID:netxfly,项目名称:wetalk,代码行数:47,代码来源:user.go


示例6: SearchPost

func SearchPost(q string, page int) ([]*models.Post, *utils.SphinxMeta, error) {
	q = filterSearchQ(q)
	if len(q) == 0 {
		return nil, nil, fmt.Errorf("empty query")
	}

	sdb, err := utils.SphinxPools.GetConn()
	if err != nil {
		return nil, nil, err
	}
	defer sdb.Close()

	pers := 20
	if page == 0 {
		page = 1
	}
	offset := (page - 1) * pers

	var pids orm.ParamsList
	query := fmt.Sprintf(`SELECT @id AS pid, updated
		FROM `+setting.SphinxIndex+`
		WHERE MATCH('`+q+`')
		ORDER BY @weight DESC, updated DESC
		LIMIT %d, %d OPTION ranker=bm25`, offset, pers)

	if _, err = sdb.RawValuesFlat(query, &pids, "pid"); err != nil {
		return nil, nil, err
	}

	var meta *utils.SphinxMeta
	if meta, err = sdb.ShowMeta(); err != nil {
		return nil, nil, err
	}
	sdb.Close()

	if len(pids) == 0 {
		return nil, meta, nil
	}

	var posts []*models.Post
	_, err = models.Posts().Filter("Id__in", pids).RelatedSel().All(&posts)
	if err != nil {
		return nil, nil, err
	}

	return posts, meta, nil
}
开发者ID:JessonChan,项目名称:wetalk,代码行数:47,代码来源:search.go


示例7: CatNavs

func (this *PostListRouter) CatNavs() {
	this.TplNames = "post/home.html"
	//check category slug and sort slug
	catSlug := this.GetString(":catSlug")
	sortSlug := this.GetString(":sortSlug")
	cat := models.Category{Slug: catSlug}
	if err := cat.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}
	qs := models.Posts().Filter("Category", &cat)
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	switch sortSlug {
	case "recent":
		qs = qs.OrderBy("-Created")
	case "hot":
		qs = qs.OrderBy("-LastReplied")
	case "cold":
		qs = qs.Filter("Replys", 0).OrderBy("-Created")
	default:
		this.Abort("404")
		return
	}
	qs = qs.Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	var posts []models.Post
	models.ListObjects(qs, &posts)

	this.Data["Category"] = &cat
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	var topics []models.Topic
	this.setTopicsOfCategory(&topics, &cat)
	this.Data["CategorySlug"] = cat.Slug
	this.Data["SortSlug"] = sortSlug
	var newBestPosts []models.Post
	this.setNewBestPostsOfCategory(&newBestPosts, &cat)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfCategory(&mostReplysPosts, &cat)
	this.setSidebarBuilletinInfo()
}
开发者ID:netxfly,项目名称:wetalk,代码行数:45,代码来源:post.go


示例8: PostBrowsersAdd

func PostBrowsersAdd(uid int, ip string, post *models.Post) {
	var key string
	if uid == 0 {
		key = ip
	} else {
		key = utils.ToStr(uid)
	}
	key = fmt.Sprintf("PCA.%d.%s", post.Id, key)
	if setting.Cache.Get(key) != nil {
		return
	}
	_, err := models.Posts().Filter("Id", post.Id).Update(orm.Params{
		"Browsers": orm.ColValue(orm.Col_Add, 1),
	})
	if err != nil {
		beego.Error("PostCounterAdd ", err)
	}
	setting.Cache.Put(key, true, 60)
}
开发者ID:netxfly,项目名称:wetalk,代码行数:19,代码来源:util.go


示例9: loadPost

func (this *PostRouter) loadPost(post *models.Post, user *models.User) bool {
	id, _ := this.GetInt(":post")
	if id > 0 {
		qs := models.Posts().Filter("Id", id)
		if user != nil {
			qs = qs.Filter("User", user.Id)
		}
		qs.RelatedSel(1).One(post)
	}

	if post.Id == 0 {
		this.Abort("404")
		return true
	}

	this.Data["Post"] = post

	return false
}
开发者ID:wildex,项目名称:wetalk,代码行数:19,代码来源:post.go


示例10: Topic

//Topic Home Page
func (this *PostListRouter) Topic() {
	this.TplNames = "post/topic.html"
	//check topic slug
	slug := this.GetString(":slug")
	topic := models.Topic{Slug: slug}
	if err := topic.Read("Slug"); err != nil {
		this.Abort("404")
		return
	}
	//get topic category
	category := models.Category{Id: topic.Category.Id}
	if err := category.Read("Id"); err != nil {
		this.Abort("404")
		return
	}

	//get posts by topic
	qs := models.Posts().Filter("Topic", &topic)
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	qs = qs.OrderBy("-LastReplied").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	var posts []models.Post
	models.ListObjects(qs, &posts)

	this.Data["Posts"] = posts
	this.Data["Topic"] = &topic
	this.Data["Category"] = &category

	//check whether added it into favorite list
	HasFavorite := false
	if this.IsLogin {
		HasFavorite = models.FollowTopics().Filter("User", &this.User).Filter("Topic", &topic).Exist()
	}
	this.Data["HasFavorite"] = HasFavorite

	//new best post
	var newBestPosts []models.Post
	this.setNewBestPostsOfTopic(&newBestPosts, &topic)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPostsOfTopic(&mostReplysPosts, &topic)
	this.setSidebarBuilletinInfo()
}
开发者ID:netxfly,项目名称:wetalk,代码行数:44,代码来源:post.go


示例11: Home

// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Home() {
	this.Data["IsHome"] = true
	this.TplName = "post/home.html"

	var cats []models.Category
	this.setCategories(&cats)

	var posts []models.Post
	qs := models.Posts().OrderBy("-Created").Limit(25).RelatedSel()
	qs = this.postsFilter(qs)

	models.ListObjects(qs, &posts)
	this.Data["Posts"] = posts

	this.Data["CategorySlug"] = "hot"

	var topics []models.Topic
	post.ListTopics(&topics)
	this.Data["Topics"] = topics
}
开发者ID:wildex,项目名称:wetalk,代码行数:21,代码来源:post.go


示例12: FavoritePosts

func (this *UserRouter) FavoritePosts() {
	this.TplNames = "user/favorite-posts.html"

	var user models.User
	if this.getUser(&user) {
		return
	}

	var postIds orm.ParamsList
	var posts []models.Post
	nums, _ := user.FavoritePosts().OrderBy("-Created").ValuesFlat(&postIds, "Post")
	if nums > 0 {
		qs := models.Posts().Filter("Id__in", postIds)
		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(setting.PostCountPerPage, cnt)
		qs = qs.OrderBy("-Created").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
		models.ListObjects(qs, &posts)
	}

	this.Data["TheUserFavoritePosts"] = posts
}
开发者ID:netxfly,项目名称:wetalk,代码行数:21,代码来源:user.go


示例13: Delete

// view for delete object
func (this *TopicAdminRouter) Delete() {
	if this.FormOnceNotMatch() {
		return
	}
	//check whether there are posts under this topic
	qs := models.Posts().Filter("Topic__id", this.object.Id)
	cnt, _ := qs.Count()
	if cnt > 0 {
		this.FlashRedirect("/admin/topic", 302, "DeleteNotAllowed")
		return
	} else {
		// delete object
		if err := this.object.Delete(); err == nil {
			this.FlashRedirect("/admin/topic", 302, "DeleteSuccess")
			return
		} else {
			beego.Error(err)
			this.Data["Error"] = err
		}
	}
}
开发者ID:netxfly,项目名称:wetalk,代码行数:22,代码来源:admin_topic.go


示例14: Topic

// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Topic() {
	slug := this.GetString(":slug")

	switch slug {
	default: // View topic.
		this.TplName = "post/topic.html"
		topic := models.Topic{Slug: slug}
		if err := topic.Read("Slug"); err != nil {
			this.Abort("404")
			return
		}

		pers := 25

		qs := models.Posts().Filter("Topic", &topic)
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

		var posts []models.Post
		models.ListObjects(qs, &posts)

		this.Data["Posts"] = posts
		this.Data["Topic"] = &topic
		this.Data["IsTopic"] = true

		HasFavorite := false
		if this.IsLogin {
			HasFavorite = models.FollowTopics().Filter("User", &this.User).Filter("Topic", &topic).Exist()
		}
		this.Data["HasFavorite"] = HasFavorite
	}
}
开发者ID:wildex,项目名称:wetalk,代码行数:37,代码来源:post.go


示例15: Navs

func (this *PostListRouter) Navs() {
	this.TplNames = "post/home.html"

	sortSlug := this.GetString(":sortSlug")
	var posts []models.Post
	qs := models.Posts()
	cnt, _ := models.CountObjects(qs)
	pager := this.SetPaginator(setting.PostCountPerPage, cnt)
	switch sortSlug {
	case "recent":
		qs = qs.OrderBy("-Created")
	case "hot":
		qs = qs.OrderBy("-LastReplied")
	case "cold":
		qs = qs.Filter("Replys", 0).OrderBy("-Created")
	default:
		this.Abort("404")
		return
	}
	qs = qs.Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
	models.ListObjects(qs, &posts)
	this.Data["Posts"] = posts

	//top nav bar data
	var cats []models.Category
	this.setCategories(&cats)
	this.Data["SortSlug"] = sortSlug
	this.Data["CategorySlug"] = "home"
	//new best posts
	var newBestPosts []models.Post
	this.setNewBestPosts(&newBestPosts)
	//most replys posts
	var mostReplysPosts []models.Post
	this.setMostReplysPosts(&mostReplysPosts)
	this.setSidebarBuilletinInfo()
}
开发者ID:netxfly,项目名称:wetalk,代码行数:36,代码来源:post.go


示例16: ListPostsOfTopic

func ListPostsOfTopic(topic *models.Topic, posts *[]models.Post) (int64, error) {
	return models.Posts().Filter("Topic", topic).RelatedSel().OrderBy("-Updated").All(posts)
}
开发者ID:netxfly,项目名称:wetalk,代码行数:3,代码来源:util.go


示例17: Navs

// Get implemented Get method for HomeRouter.
func (this *PostListRouter) Navs() {
	slug := this.GetString(":slug")

	switch slug {
	case "favs", "follow":
		if this.CheckLoginRedirect() {
			return
		}
	}

	this.Data["CategorySlug"] = slug
	this.TplName = fmt.Sprintf("post/navs/%s.html", slug)

	pers := 25

	var posts []models.Post

	switch slug {
	case "recent":
		qs := models.Posts()
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Updated").Limit(pers, pager.Offset()).RelatedSel()

		models.ListObjects(qs, &posts)

		var cats []models.Category
		this.setCategories(&cats)

	case "best":
		qs := models.Posts().Filter("IsBest", true)
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

		models.ListObjects(qs, &posts)

		var cats []models.Category
		this.setCategories(&cats)

	case "cold":
		qs := models.Posts().Filter("Replys", 0)
		qs = this.postsFilter(qs)

		cnt, _ := models.CountObjects(qs)
		pager := this.SetPaginator(pers, cnt)

		qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

		models.ListObjects(qs, &posts)

		var cats []models.Category
		this.setCategories(&cats)

	case "favs":
		var topicIds orm.ParamsList
		nums, _ := models.FollowTopics().Filter("User", &this.User.Id).OrderBy("-Created").ValuesFlat(&topicIds, "Topic")
		if nums > 0 {
			qs := models.Posts().Filter("Topic__in", topicIds)
			qs = this.postsFilter(qs)

			cnt, _ := models.CountObjects(qs)
			pager := this.SetPaginator(pers, cnt)

			qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

			models.ListObjects(qs, &posts)

			var topics []models.Topic
			nums, _ = models.Topics().Filter("Id__in", topicIds).Limit(8).All(&topics)
			this.Data["Topics"] = topics
			this.Data["TopicsMore"] = nums >= 8
		}

	case "follow":
		var userIds orm.ParamsList
		nums, _ := this.User.FollowingUsers().OrderBy("-Created").ValuesFlat(&userIds, "FollowUser")
		if nums > 0 {
			qs := models.Posts().Filter("User__in", userIds)
			qs = this.postsFilter(qs)

			cnt, _ := models.CountObjects(qs)
			pager := this.SetPaginator(pers, cnt)

			qs = qs.OrderBy("-Created").Limit(pers, pager.Offset()).RelatedSel()

			models.ListObjects(qs, &posts)
		}
	}

	this.Data["Posts"] = posts
}
开发者ID:wildex,项目名称:wetalk,代码行数:99,代码来源:post.go


示例18: ObjectQs

func (this *PostAdminRouter) ObjectQs() orm.QuerySeter {
	return models.Posts().RelatedSel()
}
开发者ID:JessonChan,项目名称:wetalk,代码行数:3,代码来源:admin_post.go


示例19: setNewBestPostsOfCategory

//Get new best posts by category
func (this *PostListRouter) setNewBestPostsOfCategory(posts *[]models.Post, cat *models.Category) {
	qs := models.Posts()
	qs = qs.Filter("IsBest", true).Filter("Category__id", cat.Id).OrderBy("-Created").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["NewBestPosts"] = posts
}
开发者ID:netxfly,项目名称:wetalk,代码行数:7,代码来源:post.go


示例20: setNewBestPostsOfTopic

//Get new best posts by topic
func (this *PostListRouter) setNewBestPostsOfTopic(posts *[]models.Post, topic *models.Topic) {
	qs := models.Posts()
	qs = qs.Filter("IsBest", true).Filter("Topic__id", topic.Id).OrderBy("-Created").Limit(10)
	models.ListObjects(qs, posts)
	this.Data["NewBestPosts"] = posts
}
开发者ID:netxfly,项目名称:wetalk,代码行数:7,代码来源:post.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.Category类代码示例发布时间:2022-05-24
下一篇:
Golang redis.Bool函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap