本文整理汇总了Golang中github.com/lisijie/goblog/models.Tag类的典型用法代码示例。如果您正苦于以下问题:Golang Tag类的具体用法?Golang Tag怎么用?Golang Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tag类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Category
//分类查看
func (this *MainController) Category() {
var (
page int
pagesize int
name string
err error
count int64
result map[string][]*models.Post
)
name = this.Ctx.Input.Param(":name")
if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
page = 1
}
if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
pagesize = 20
} else {
pagesize *= 2
}
o := orm.NewOrm()
tag := new(models.Tag)
tag.Name = name
if o.Read(tag, "Name") != nil {
this.Abort("404")
}
count, _ = o.QueryTable(&models.TagPost{}).Filter("tagid", tag.Id).Filter("poststatus", 0).Count()
result = make(map[string][]*models.Post)
if count > 0 {
var tp []*models.TagPost
var list []*models.Post
var pids []int64 = make([]int64, 0)
o.QueryTable(&models.TagPost{}).Filter("tagid", tag.Id).Filter("poststatus", 0).OrderBy("-posttime").Limit(pagesize, (page-1)*pagesize).All(&tp)
for _, v := range tp {
pids = append(pids, v.Postid)
}
o.QueryTable(&models.Post{}).Filter("id__in", pids).All(&list)
for _, v := range list {
year := v.Posttime.Format("2006")
if _, ok := result[year]; !ok {
result[year] = make([]*models.Post, 0)
}
result[year] = append(result[year], v)
}
}
this.Data["tag"] = tag
this.Data["page"] = page
this.Data["pagesize"] = pagesize
this.Data["count"] = count
this.Data["result"] = result
this.Data["pagebar"] = models.NewPager(int64(page), int64(count), int64(pagesize), "/category/"+url.QueryEscape(tag.Name)).ToString()
this.setHeadMetas(tag.Name, tag.Name, tag.Name)
this.display("category")
}
开发者ID:Neeke,项目名称:goblog,代码行数:61,代码来源:main.go
示例2: list
//标签列表
func (this *TagController) list() {
var page int64
var pagesize int64 = 10
var list []*models.Tag
var tag models.Tag
if page, _ = this.GetInt("page"); page < 1 {
page = 1
}
offset := (page - 1) * pagesize
count, _ := tag.Query().Count()
if count > 0 {
tag.Query().OrderBy("-count").Limit(pagesize, offset).All(&list)
}
this.Data["count"] = count
this.Data["list"] = list
this.Data["pagebar"] = models.NewPager(page, count, pagesize, "/admin/tag", true).ToString()
this.display("tag_list")
}
开发者ID:Neeke,项目名称:goblog,代码行数:22,代码来源:tag.go
示例3: Save
//保存
func (this *ArticleController) Save() {
var (
id int64 = 0
title string = strings.TrimSpace(this.GetString("title"))
content string = this.GetString("content")
tags string = strings.TrimSpace(this.GetString("tags"))
urlname string = strings.TrimSpace(this.GetString("urlname"))
color string = strings.TrimSpace(this.GetString("color"))
status int64 = 0
istop int8 = 0
urltype int8 = 1
post models.Post
)
if title == "" {
this.showmsg("标题不能为空!")
}
id, _ = this.GetInt("id")
status, _ = this.GetInt("status")
if this.GetString("istop") == "1" {
istop = 1
}
if this.GetString("urltype") == "2" {
urltype = 2
}
if status != 1 && status != 2 {
status = 0
}
addtags := make([]string, 0)
//标签过滤
if tags != "" {
tagarr := strings.Split(tags, ",")
for _, v := range tagarr {
if tag := strings.TrimSpace(v); tag != "" {
exists := false
for _, vv := range addtags {
if vv == tag {
exists = true
break
}
}
if !exists {
addtags = append(addtags, tag)
}
}
}
}
if id < 1 {
post.Userid = this.userid
post.Author = this.username
post.Posttime = this.getTime()
post.Insert()
} else {
post.Id = id
if post.Read() != nil {
goto RD
}
if post.Tags != "" {
var tagobj models.Tag
var tagpostobj models.TagPost
oldtags := strings.Split(strings.Trim(post.Tags, ","), ",")
//标签统计-1
tagobj.Query().Filter("name__in", oldtags).Update(orm.Params{"count": orm.ColValue(orm.Col_Minus, 1)})
//删掉tag_post表的记录
tagpostobj.Query().Filter("postid", post.Id).Delete()
}
}
if len(addtags) > 0 {
for _, v := range addtags {
tag := models.Tag{Name: v}
if tag.Read("Name") == orm.ErrNoRows {
tag.Count = 1
tag.Insert()
} else {
tag.Count += 1
tag.Update("Count")
}
tp := models.TagPost{Tagid: tag.Id, Postid: post.Id, Poststatus: int8(status), Posttime: this.getTime()}
tp.Insert()
}
post.Tags = "," + strings.Join(addtags, ",") + ","
}
post.Status = int8(status)
post.Title = title
post.Color = color
post.Istop = istop
post.Content = content
post.Urlname = urlname
post.Urltype = urltype
post.Updated = this.getTime()
post.Update()
RD:
//.........这里部分代码省略.........
开发者ID:Neeke,项目名称:goblog,代码行数:101,代码来源:article.go
示例4: batch
//批量操作
func (this *TagController) batch() {
ids := this.GetStrings("ids[]")
op := this.GetString("op")
idarr := make([]int64, 0)
for _, v := range ids {
if id, _ := strconv.Atoi(v); id > 0 {
idarr = append(idarr, int64(id))
}
}
switch op {
case "upcount": //更新统计
for _, id := range idarr {
obj := models.Tag{Id: id}
if obj.Read() == nil {
obj.UpCount()
}
}
case "merge": //合并到
toname := strings.TrimSpace(this.GetString("toname"))
if toname != "" && len(idarr) > 0 {
tag := new(models.Tag)
tag.Name = toname
if tag.Read("name") != nil {
tag.Count = 0
tag.Insert()
}
for _, id := range idarr {
obj := models.Tag{Id: id}
if obj.Read() == nil {
obj.MergeTo(tag)
obj.Delete()
}
}
tag.UpCount()
}
case "delete": //批量删除
for _, id := range idarr {
obj := models.Tag{Id: id}
if obj.Read() == nil {
obj.Delete()
}
}
}
this.Redirect("/admin/tag", 302)
}
开发者ID:Neeke,项目名称:goblog,代码行数:49,代码来源:tag.go
示例5: Category
//分类查看
func (this *MainController) Category() {
var (
page int
pagesize int
name string
err error
count int64
result map[string][]*models.Post
)
name = this.Ctx.Input.Param(":name")
if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
page = 1
}
if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
pagesize = 20
} else {
pagesize *= 2
}
tagpost := new(models.TagPost)
tag := new(models.Tag)
tag.Name = name
if tag.Read("Name") != nil {
this.Abort("404")
}
query := tagpost.Query().Filter("tag_id", tag.Id).Filter("post_status", 0)
count, _ = query.Count()
result = make(map[string][]*models.Post)
if count > 0 {
var tp []*models.TagPost
var list []*models.Post
var pids []int = make([]int, 0)
query.OrderBy("-post_time").Limit(pagesize, (page-1)*pagesize).All(&tp)
for _, v := range tp {
pids = append(pids, v.PostId)
}
new(models.Post).Query().Filter("id__in", pids).All(&list)
for _, v := range list {
year := v.PostTime.Format("2006")
if _, ok := result[year]; !ok {
result[year] = make([]*models.Post, 0)
}
result[year] = append(result[year], v)
}
}
this.Data["tag"] = tag
this.Data["page"] = page
this.Data["pagesize"] = pagesize
this.Data["count"] = count
this.Data["result"] = result
this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, tag.Link()).ToString()
this.setHeadMetas(tag.Name, tag.Name, tag.Name)
this.display("category")
}
开发者ID:flying99999,项目名称:goblog-1,代码行数:62,代码来源:main.go
注:本文中的github.com/lisijie/goblog/models.Tag类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论