Exemple #1
0
func (this *Tag) Get() {
	tag := this.Ctx.Input.Param(":tag")

	if tag == "" {
		this.Redirect("/", 302)
	}

	this.TplNames = "tag.html"

	currentPage := 1
	if page, err := strconv.Atoi(this.Input().Get("p")); err == nil {
		currentPage = page
	}

	totalCount := 1
	articles := []article.Article{}
	model.ArticleC.Do(func(c *mgo.Collection) {
		q := c.Find(bson.M{"tags": tag}).Sort("-createtime")
		totalCount, _ = q.Count()
		q.Skip(limit * (currentPage - 1)).Limit(limit).All(&articles)
	})

	this.Data["articles"] = articles
	this.Data["tag"] = "Tag:" + tag

	pagination.SetPaginator(this.Ctx, limit, int64(totalCount))
}
Exemple #2
0
func (this *AdminController) AllPosts() {
	this.TplName = "admin-posts.tpl"
	this.Data["PageTitle"] = fmt.Sprintf("All Posts - %s - Admin - %s", this.loggedUser.DisplayName, blogTitle)

	post_count, err := models.NewPostModel().Count("", nil, true)
	if err != nil {
		panic(err)
	}
	paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)
	posts, _ := models.NewPostModel().Offset("", nil, "-PostId", paginator.Offset(), postsPerPage, true, false, true)
	this.Data["Posts"] = posts

	views := make(map[int]int)
	bot_views := make(map[int]int)
	for _, post := range posts {
		for _, view := range post.PostViews {
			if view.ViewedBy == "human" {
				views[post.PostId] = view.Views
			} else if view.ViewedBy == "bot" {
				bot_views[post.PostId] = view.Views
			}
		}
	}
	this.Data["Views"] = views
	this.Data["BotViews"] = bot_views
}
// search list
// @router /list.html [get]
func (this *IndexController) List() {
	var err error

	this.TplNames = "front/list.html"

	numPerPage := 10
	keywords := this.GetString("keywords")
	all := strings.HasPrefix(keywords, "all:")
	if all {
		keywords = strings.Split(keywords, "all:")[1]
	}

	maxCount, _ := models.SearchCount(keywords, all)
	this.Data["count"] = maxCount

	paginator := pagination.SetPaginator(this.Ctx, numPerPage, maxCount)
	data, err := models.Search(keywords, all, numPerPage, paginator.Offset(), "-create_at")
	if err != nil {
		beego.Error(err)
	}

	for _, torrent := range data {
		if len(torrent.FileList) > 5 {
			torrent.FileList = torrent.FileList[:5]
		}
	}

	this.Data["torrents"] = data
	this.Render()
}
Exemple #4
0
func (this *AuthorController) ByName() {
	this.TplName = "author.tpl"

	author_name := this.Ctx.Input.Param(":name")

	if post_count, err := models.NewPostModel().Count("Author__AuthorName", author_name); err == nil {
		paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)
		if author, err := models.NewAuthorModel().ByName(author_name); err == nil {
			this.Data["Author"] = author
			posts, err := models.NewPostModel().ByAuthorId(author.AuthorId, "-PostId", paginator.Offset(), postsPerPage, false, true, true)
			if err != nil {
				panic(err)
			}

			this.SetPostViews(posts)
			this.LoadSidebar([]string{"LatestComments", "MostPopular"})

			this.Data["Posts"] = posts
			this.Data["PageTitle"] = fmt.Sprintf("%s - Author - %s", author.DisplayName, blogTitle)
		} else {
			this.Abort("404")
		}
	} else {
		panic(err)
	}
}
Exemple #5
0
func (this *TopicController) TopicList() {
	this.TplNames = "topicList.html"

	currentPage := 1
	if page, err := strconv.Atoi(this.Input().Get("p")); err == nil {
		currentPage = page
	}

	topics, totalNum := topic.GetTopicList(currentPage)
	this.Data["topics"] = topics
	pagination.SetPaginator(this.Ctx, enum.CONST.PERPAGE, totalNum)
}
Exemple #6
0
//草稿列表
func (this *Article) DraftList() {
	this.TplNames = "draft_list.html"
	this.Data["isDraft"] = true

	currentPage := 1
	//获取上一页的页码
	if page, err := strconv.Atoi(this.Input().Get("p")); err == nil {
		currentPage = page
	}

	var count int64
	this.Data["topics"], count = article.GetAllDrafts(limit, currentPage)
	pagination.SetPaginator(this.Ctx, limit, count)
}
Exemple #7
0
func (this *CategoryController) Index() {
	perPage := 1000
	o := orm.NewOrm()
	var categorys []models.Category
	category := new(models.Category)
	qs := o.QueryTable(category)
	num, _ := qs.Count()
	paginator := pagination.SetPaginator(this.Ctx, perPage, num)
	qs = qs.Limit(perPage, paginator.Offset())
	qs.All(&categorys)
	this.Data["categorys"] = categorys
	this.Data["paginator"] = paginator
	this.TplNames = "admin/category/index.tpl"
}
Exemple #8
0
func (this *ContentController) Index() {
	perPage := 1000
	var contents []models.Content
	o := orm.NewOrm()
	qs := o.QueryTable(new(models.Content))
	num, _ := qs.Count()
	paginator := pagination.SetPaginator(this.Ctx, perPage, num)
	qs = qs.Limit(perPage, paginator.Offset())
	qs.RelatedSel().All(&contents)

	beego.Debug(contents)

	this.Data["contents"] = contents
	this.Data["paginator"] = paginator

	this.TplNames = "admin/content/index.tpl"
}
Exemple #9
0
func (this *Home) Index() {
	this.TplNames = "home.html"
	this.Data["Title"] = "首页"

	currentPage := 1
	//获取上一页的页码
	if page, err := strconv.Atoi(this.Input().Get("p")); err == nil {
		currentPage = page
	}

	articleList, count := article.GetAllArticles(pageLimit, currentPage)

	pagination.SetPaginator(this.Ctx, pageLimit, count)

	this.Data["topicList"] = articleList

	this.Data["categoryList"] = article.GetCategories(false)
}
Exemple #10
0
//文章列表
func (this *Index) Get() {
	this.TplNames = "index.html"

	currentPage := 1
	if page, err := strconv.Atoi(this.Input().Get("p")); err == nil {
		currentPage = page
	}

	articles := []article.Article{}
	totalCount := 1
	model.ArticleC.Do(func(c *mgo.Collection) {
		q := c.Find(nil).Sort("-createtime")
		totalCount, _ = q.Count()
		q.Skip(limit * (currentPage - 1)).Limit(limit).All(&articles)
	})

	this.Data["articles"] = articles
	pagination.SetPaginator(this.Ctx, limit, int64(totalCount))
}
Exemple #11
0
func (this *MainController) Get() {
	post_count, err := models.NewPostModel().Count("", "")
	if err != nil {
		panic(err)
	}
	paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)

	posts, err := models.NewPostModel().Offset("", nil, "-PostId", paginator.Offset(), postsPerPage, false, true, true)
	if err != nil {
		panic(err)
	}
	this.Data["Posts"] = posts

	this.SetPostViews(posts)
	this.LoadSidebar([]string{"LatestComments", "MostPopular", "Links", "TagCloud"})

	this.Data["PageTitle"] = fmt.Sprintf("%s %s", blogTitle, blogDesc)
	this.TplName = "home.tpl"
}
Exemple #12
0
func (this *ErrorController) Error404() {
	post_count, err := models.NewPostModel().Count("", "")
	if err != nil {
		panic(err)
	}
	paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)

	posts, err := models.NewPostModel().Offset("", nil, "-PostId", paginator.Offset(), postsPerPage, false, true, true)
	if err != nil {
		panic(err)
	}

	this.SetPostViews(posts)
	this.LoadSidebar([]string{"LatestComments", "MostPopular"})

	this.Data["Posts"] = posts
	this.Data["PageTitle"] = blogTitle
	this.Data["Content"] = "404 - 您要找的页面不见啦,不如看看其它内容吧"
	this.TplName = "404.tpl"
}
Exemple #13
0
//
//根据分类列出文章 todo 错误处理
func (this *Home) Category() {
	this.TplNames = "home.html"

	var id int
	var err error
	if id, err = strconv.Atoi(this.Input().Get("id")); err == nil {

	}

	currentPage := 1
	//获取上一页的页码
	if page, err := strconv.Atoi(this.Input().Get("p")); err == nil {
		currentPage = page
	}

	var count int64
	this.Data["topicList"], count = article.GetArticlesByCategoryId(int64(id), pageLimit, int64(currentPage)) //todo

	this.Data["categoryList"] = article.GetCategories(false)

	pagination.SetPaginator(this.Ctx, pageLimit, count)
}
Exemple #14
0
func (this *CompanyController) Index() {
	perPage := 20
	//paginator := pagination.SetPaginator(this.Ctx,perPage,int64(20))
	var companys []models.Company
	o := orm.NewOrm()
	company := new(models.Company)
	qs := o.QueryTable(company)
	//qs.Filter("","")
	nums, _ := qs.Count()
	//nums := int64(10)
	fmt.Print(nums, companys)
	beego.Debug(nums)

	paginator := pagination.SetPaginator(this.Ctx, perPage, nums)
	qs = qs.Limit(perPage, paginator.Offset())

	beego.Debug(paginator.Offset())
	qs.All(&companys)
	this.Data["companys"] = companys
	this.Data["paginator"] = paginator
	this.TplNames = "admin/company/index.tpl"
}
Exemple #15
0
//list of candidates
func (c *Cand) Index() {
	var cands []M.Cand
	var deps []M.Dep
	var wF M.Where

	depF, err := strconv.Atoi(c.Input().Get("dep"))

	if depF > 0 {
		wF = M.Where{And: M.W{"Dep": depF}}
	}

	cnt, err := DM.Count(&M.Cand{}, wF)
	if err != nil {
		beego.Error(err)
	}

	perPage := 10
	paginator := pagination.SetPaginator(c.Ctx, perPage, cnt)

	//TODO properly handle db errors
	err = DM.FindAll(&M.Cand{}, &cands, M.Sf{}, wF, M.NewParams(M.Params{Offset: paginator.Offset(), Limit: perPage, Sort: "Name,LName ASC"}))
	if err != nil {
		beego.Error(err)
		return
	}
	err = DM.FindAll(&M.Dep{}, &deps, M.Sf{}, M.Where{}, M.NewParams(M.Params{Sort: "Title ASC"}))
	if err != nil {
		beego.Error(err)
		return
	}
	m := make(map[int]string)
	for _, v := range deps {
		m[v.Id] = v.Title
	}
	c.Data["deps"] = m
	c.Data["depFilter"] = depF
	c.Data["cands"] = cands
	c.Data["title"] = T("cand", 2)
}
Exemple #16
0
func (this *TagController) ByName() {
	this.TplName = "home.tpl"
	tag_name := this.Ctx.Input.Param(":tag")

	post_count, err := models.NewPostModel().Count("Tags__Tag__TagSlug", tag_name)
	if err != nil {
		panic(err)
	}
	paginator := pagination.SetPaginator(this.Ctx, postsPerPage, post_count)

	posts, err := models.NewPostModel().ByTagName(tag_name, "-PostId", paginator.Offset(), postsPerPage, false, true, true)
	if err != nil {
		this.Abort("404")
	}
	this.Data["Posts"] = posts

	this.SetPostViews(posts)
	this.LoadSidebar([]string{"LatestComments", "MostPopular"})

	if tag, err := models.NewTagModel().BySlug(tag_name); err == nil {
		this.Data["Content"] = fmt.Sprintf("Tag - %s", tag.TagName)
		this.Data["PageTitle"] = fmt.Sprintf("%s - Tag - %s", tag.TagName, blogTitle)
	}
}
Exemple #17
0
func (self *QMainController) Get() {
	self.TplNames = "q/index.html"

	self.LayoutSections["Heads"] = "q/head.html"
	self.LayoutSections["Scripts"] = "q/scripts.html"

	//ipage, _ := self.GetInt(":page")
	//page := int(ipage)

	tab := template.HTMLEscapeString(strings.TrimSpace(self.GetString(":tab")))
	order := "id"
	//url := "/"
	if tab == "lastest" {
		//url = "/q/lastest/"
		self.Data["tab"] = "lastest"
	} else if tab == "hotness" {
		//url = "/q/hotness/"
		order = "hotness"
		self.Data["tab"] = "hotness"
	} else if tab == "unanswered" {
		//url = "/q/unanswered/"
		order = "unanswered"
		self.Data["tab"] = "unanswered"
	} else {
		//url = "/q/lastest/"
		order = "id"
		self.Data["tab"] = "lastest"
	}

	pagesize := 15
	count, err := models.GetQuestionsCount(0, pagesize, order)
	if err != nil {
		return
	}
	paginator := pagination.SetPaginator(self.Ctx, pagesize, count)

	if qts, err := models.GetQuestions(paginator.Offset(), pagesize, order); err == nil {
		results_count := len(*qts)
		qinfo := make([]QuestionWithInfo, results_count)
		for i, v := range *qts {
			qinfo[i].Q = v

			//
			qinfo[i].Avatar = models.GetAvatar(v.Uid)

			//
			if v.Tags != "" {
				qinfo[i].Tags = utils.Tags(v.Tags, ",")
				qinfo[i].LenTags = len(qinfo[i].Tags) - 1
			} else {
				qinfo[i].LenTags = 0
			}
		}
		self.Data["questions"] = qinfo
	} else {
		fmt.Println("首页推荐榜单 数据查询出错", err)
	}

	// lastest replied questions
	qts, err := models.GetLastestReplyQuestions(10)
	self.Data["lastest_replys"] = *qts
}