| @@ -21,3 +21,11 @@ type Dataset struct { | |||||
| Attachments []*Attachment `xorm:"-"` | Attachments []*Attachment `xorm:"-"` | ||||
| } | } | ||||
| func CreateDataset(dataset *Dataset) (err error) { | |||||
| if _, err = x.Insert(dataset); err != nil { | |||||
| return err | |||||
| } | |||||
| return nil | |||||
| } | |||||
| @@ -0,0 +1,21 @@ | |||||
| package auth | |||||
| import ( | |||||
| "gitea.com/macaron/binding" | |||||
| "gitea.com/macaron/macaron" | |||||
| ) | |||||
| // CreateDatasetForm form for dataset page | |||||
| type CreateDatasetForm struct { | |||||
| Title string `binding:"Required"` | |||||
| Category string `binding:"Required"` | |||||
| Description string `binding:"Required;MaxSize(254)"` | |||||
| License string `binding:"OmitEmpty;MaxSize(64)"` | |||||
| Task string | |||||
| Release_id int64 `xorm:"INDEX"` | |||||
| } | |||||
| // Validate validates the fields | |||||
| func (f *CreateDatasetForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | |||||
| return validate(errs, ctx.Data, f, ctx.Locale) | |||||
| } | |||||
| @@ -626,7 +626,7 @@ description = Description | |||||
| create_dataset = Create Dataset | create_dataset = Create Dataset | ||||
| category = Category | category = Category | ||||
| task = Task | task = Task | ||||
| licience = Licience | |||||
| Licenses = Licenses | |||||
| file = Dataset File | file = Dataset File | ||||
| [repo] | [repo] | ||||
| @@ -625,7 +625,7 @@ description = 描述 | |||||
| create_dataset = 创建数据集 | create_dataset = 创建数据集 | ||||
| category = 分类 | category = 分类 | ||||
| task = 针对的具体任务 | task = 针对的具体任务 | ||||
| licience = Licience | |||||
| Licenses = Licenses | |||||
| file = 数据集文件 | file = 数据集文件 | ||||
| [repo] | [repo] | ||||
| @@ -1,6 +1,8 @@ | |||||
| package dataset | package dataset | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/models" | |||||
| "code.gitea.io/gitea/modules/auth" | |||||
| "code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
| "code.gitea.io/gitea/modules/context" | "code.gitea.io/gitea/modules/context" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| @@ -20,6 +22,62 @@ func Create(ctx *context.Context) { | |||||
| log.Debug("[dataset] Create...\n") | log.Debug("[dataset] Create...\n") | ||||
| ctx.HTML(200, tplCreate) | ctx.HTML(200, tplCreate) | ||||
| } | } | ||||
| // func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) { | |||||
| // switch { | |||||
| // case models.IsErrReachLimitOfRepo(err): | |||||
| // ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form) | |||||
| // case models.IsErrRepoAlreadyExist(err): | |||||
| // ctx.Data["Err_RepoName"] = true | |||||
| // ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form) | |||||
| // case models.IsErrNameReserved(err): | |||||
| // ctx.Data["Err_RepoName"] = true | |||||
| // ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form) | |||||
| // case models.IsErrNamePatternNotAllowed(err): | |||||
| // ctx.Data["Err_RepoName"] = true | |||||
| // ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) | |||||
| // default: | |||||
| // ctx.ServerError(name, err) | |||||
| // } | |||||
| // } | |||||
| func CreatePost(ctx *context.Context, form auth.CreateDatasetForm) { | |||||
| ctx.Data["Title"] = ctx.Tr("new_dataset") | |||||
| ctxUser := ctx.User | |||||
| if ctx.HasError() { | |||||
| ctx.HTML(200, tplCreate) | |||||
| return | |||||
| } | |||||
| var err error | |||||
| opts := models.Dataset{ | |||||
| Title: form.Title, | |||||
| Category: form.Category, | |||||
| Description: form.Description, | |||||
| License: form.License, | |||||
| Task: form.Task, | |||||
| Release_id: form.Release_id, | |||||
| User_id: ctxUser.ID, | |||||
| Status: 0, | |||||
| } | |||||
| log.Debug("======================================") | |||||
| log.Debug("%#v", opts) | |||||
| log.Debug("======================================") | |||||
| // if !opts.IsValid() { | |||||
| // ctx.RenderWithErr(ctx.Tr("repo.template.one_item"), tplCreate, form) | |||||
| // return | |||||
| // } | |||||
| if err = models.CreateDataset(&opts); err != nil { | |||||
| log.Error("%v", err) | |||||
| } | |||||
| // handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form) | |||||
| } | |||||
| func Delete(ctx *context.Context) { | func Delete(ctx *context.Context) { | ||||
| log.Debug("[dataset] Delete...\n") | log.Debug("[dataset] Delete...\n") | ||||
| } | } | ||||
| @@ -1004,6 +1004,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Group("/datasets", func() { | m.Group("/datasets", func() { | ||||
| m.Get("", dataset.MyList) | m.Get("", dataset.MyList) | ||||
| m.Get("/create", dataset.Create) | m.Get("/create", dataset.Create) | ||||
| m.Post("/create", bindIgnErr(auth.CreateDatasetForm{}), dataset.CreatePost) | |||||
| m.Post("/delete", dataset.Delete) | m.Post("/delete", dataset.Delete) | ||||
| }, ignSignIn) | }, ignSignIn) | ||||
| // ***** END: DataSet***** | // ***** END: DataSet***** | ||||
| @@ -11,7 +11,7 @@ | |||||
| {{template "base/alert" .}} | {{template "base/alert" .}} | ||||
| <div class="inline required field"> | <div class="inline required field"> | ||||
| <label>{{.i18n.Tr "dataset.title"}}</label> | <label>{{.i18n.Tr "dataset.title"}}</label> | ||||
| <input name="title" placeholder="{{.i18n.Tr "dataset.title"}}" value="{{.title}}" autofocus required maxlength="255"> | |||||
| <input name="title" placeholder='{{.i18n.Tr "dataset.title"}}' value="{{.title}}" autofocus required maxlength="255"> | |||||
| </div> | </div> | ||||
| <div class="inline field"> | <div class="inline field"> | ||||
| @@ -35,12 +35,10 @@ | |||||
| <div class="inline required field"> | <div class="inline required field"> | ||||
| <label>{{.i18n.Tr "dataset.category"}}</label> | <label>{{.i18n.Tr "dataset.category"}}</label> | ||||
| <div class="ui selection owner dropdown"> | |||||
| <div class="ui selection dropdown"> | |||||
| <input type="hidden" name="category" id="category" value="{{.category}}" required> | <input type="hidden" name="category" id="category" value="{{.category}}" required> | ||||
| <span class="text" style="min-width:20vw" title="自然语言处理"> | |||||
| 自然语言处理 | |||||
| </span> | |||||
| <i class="dropdown icon"></i> | <i class="dropdown icon"></i> | ||||
| <div class="default text" style="min-width:20vw">{{.i18n.Tr "dataset.category"}}</div> | |||||
| <div class="menu"> | <div class="menu"> | ||||
| <div class="item" data-value="计算机视觉、自然语言处理"> | <div class="item" data-value="计算机视觉、自然语言处理"> | ||||
| 计算机视觉、自然语言处理 | 计算机视觉、自然语言处理 | ||||
| @@ -57,11 +55,9 @@ | |||||
| <div class="inline required field"> | <div class="inline required field"> | ||||
| <label>{{.i18n.Tr "dataset.task"}}</label> | <label>{{.i18n.Tr "dataset.task"}}</label> | ||||
| <div class="ui selection owner dropdown"> | |||||
| <div class="ui selection dropdown"> | |||||
| <input type="hidden" name="task" id="task" value="{{.task}}" required> | <input type="hidden" name="task" id="task" value="{{.task}}" required> | ||||
| <span class="text" style="min-width:20vw" title="视觉问答"> | |||||
| 视觉问答 | |||||
| </span> | |||||
| <div class="default text" style="min-width:20vw">{{.i18n.Tr "dataset.task"}}</div> | |||||
| <i class="dropdown icon"></i> | <i class="dropdown icon"></i> | ||||
| <div class="menu"> | <div class="menu"> | ||||
| <div class="item" data-value="遥感图像理解"> | <div class="item" data-value="遥感图像理解"> | ||||
| @@ -81,12 +77,10 @@ | |||||
| </div> | </div> | ||||
| <div class="inline required field"> | <div class="inline required field"> | ||||
| <label>{{.i18n.Tr "dataset.licience"}}</label> | |||||
| <label>{{.i18n.Tr "dataset.licenses"}}</label> | |||||
| <div class="ui selection owner dropdown"> | <div class="ui selection owner dropdown"> | ||||
| <input type="hidden" name="licience" id="licience" value="{{.licience}}" required> | |||||
| <span class="text" style="min-width:20vw" data-value="MIT"> | |||||
| MIT | |||||
| </span> | |||||
| <input type="hidden" name="licenses" id="licenses" value="{{.licenses}}" required> | |||||
| <div class="default text" style="min-width:20vw">{{.i18n.Tr "dataset.licenses"}}</div> | |||||
| <i class="dropdown icon"></i> | <i class="dropdown icon"></i> | ||||
| <div class="menu"> | <div class="menu"> | ||||
| <div class="item" data-value="Creative Commons CC BY 4.0"> | <div class="item" data-value="Creative Commons CC BY 4.0"> | ||||