stars.go 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "github.com/Unknwon/paginater"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/middleware"
  10. )
  11. const (
  12. STARS base.TplName = "repo/stars"
  13. )
  14. func Stars(ctx *middleware.Context) {
  15. ctx.Data["Title"] = ctx.Tr("repos.stars")
  16. page := ctx.QueryInt("page")
  17. if page <= 0 {
  18. page = 1
  19. }
  20. ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumStars, models.ItemsPerPage, page, 5)
  21. stars, err := ctx.Repo.Repository.GetStars(ctx.QueryInt("page"))
  22. if err != nil {
  23. ctx.Handle(500, "GetStars", err)
  24. return
  25. }
  26. if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumStars {
  27. ctx.Handle(404, "ctx.Repo.Repository.NumStars", nil)
  28. return
  29. }
  30. ctx.Data["Stars"] = stars
  31. ctx.HTML(200, STARS)
  32. }