You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dataset.go 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package repo
  2. import (
  3. "code.gitea.io/gitea/models"
  4. "code.gitea.io/gitea/modules/auth"
  5. "code.gitea.io/gitea/modules/base"
  6. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. const (
  10. tplIndex base.TplName = "repo/datasets/index"
  11. )
  12. func DatasetIndex(ctx *context.Context) {
  13. ctx.Data["PageIsDataset"] = true
  14. ctx.Data["Title"] = ctx.Tr("dataset.show_dataset")
  15. ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets"
  16. user := ctx.User
  17. dataset, err := models.GetDatasetByID(5)
  18. if err != nil {
  19. ctx.NotFound("GetDataset", err)
  20. return
  21. }
  22. err = models.GeDatasetAttachments(dataset)
  23. if err != nil {
  24. ctx.ServerError("GetDatasetAttachments", err)
  25. return
  26. }
  27. isOwner := (ctx.User != nil && dataset.UserID == user.ID)
  28. ctx.Data["dataset"] = dataset
  29. ctx.Data["IsOwner"] = isOwner
  30. ctx.HTML(200, tplIndex)
  31. }
  32. func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) {
  33. ctx.Data["PageIsDataset"] = true
  34. ctx.Data["Title"] = ctx.Tr("dataset.edit_dataset")
  35. rel, err := models.GetDatasetByID(5)
  36. ctx.Data["dataset"] = rel
  37. if err != nil {
  38. ctx.ServerError("GetDataset", err)
  39. return
  40. }
  41. if ctx.HasError() {
  42. ctx.Data["Error"] = true
  43. ctx.HTML(200, tplIndex)
  44. return
  45. }
  46. rel.Title = form.Title
  47. rel.Description = form.Description
  48. rel.Category = form.Category
  49. rel.Task = form.Task
  50. rel.License = form.License
  51. if err = models.UpdateDataset(models.DefaultDBContext(), rel); err != nil {
  52. ctx.Data["Error"] = true
  53. ctx.HTML(200, tplIndex)
  54. log.Error("%v", err)
  55. }
  56. ctx.Redirect(ctx.Repo.RepoLink + "/datasets")
  57. }