|
- package repo
-
- import (
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/auth"
- "code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/log"
- )
-
- const (
- tplIndex base.TplName = "repo/datasets/index"
- )
-
- func DatasetIndex(ctx *context.Context) {
- ctx.Data["PageIsDataset"] = true
- ctx.Data["Title"] = ctx.Tr("dataset.show_dataset")
- ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets"
- user := ctx.User
- dataset, err := models.GetDatasetByID(5)
- if err != nil {
- ctx.NotFound("GetDataset", err)
- return
- }
-
- err = models.GeDatasetAttachments(dataset)
- if err != nil {
- ctx.ServerError("GetDatasetAttachments", err)
- return
- }
-
- isOwner := (ctx.User != nil && dataset.UserID == user.ID)
-
- ctx.Data["dataset"] = dataset
- ctx.Data["IsOwner"] = isOwner
-
- ctx.HTML(200, tplIndex)
- }
-
- func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) {
- ctx.Data["PageIsDataset"] = true
-
- ctx.Data["Title"] = ctx.Tr("dataset.edit_dataset")
-
- rel, err := models.GetDatasetByID(5)
- ctx.Data["dataset"] = rel
-
- if err != nil {
- ctx.ServerError("GetDataset", err)
- return
- }
-
- if ctx.HasError() {
- ctx.Data["Error"] = true
- ctx.HTML(200, tplIndex)
- return
- }
-
- rel.Title = form.Title
- rel.Description = form.Description
- rel.Category = form.Category
- rel.Task = form.Task
- rel.License = form.License
- if err = models.UpdateDataset(models.DefaultDBContext(), rel); err != nil {
- ctx.Data["Error"] = true
- ctx.HTML(200, tplIndex)
- log.Error("%v", err)
- }
- ctx.Redirect(ctx.Repo.RepoLink + "/datasets")
- }
|