//@URL: /contests @method: GET func (c *ContestController) Index() { restweb.Logger.Debug("Contest List") CModel := model.ContestModel{} conetestList, err := CModel.List(nil) if err != nil { c.Error(err.Error(), 500) return } c.Output["Contest"] = conetestList c.Output["Time"] = restweb.GetTime() c.Output["Title"] = "Contest List" c.Output["IsContest"] = true c.Output["Privilege"] = c.Privilege c.RenderTemplate("view/layout.tpl", "view/contest_list.tpl") }
// 列出特定数量的问题?pid=<pid>&titile=<titile>&source=<source>&page=<page> //@URL:/problems @method:GET func (pc *ProblemController) List() { restweb.Logger.Debug(pc.R.RemoteAddr + "visit Problem List") qry := make(map[string]string) url := "/problems?" // Search if v, ok := pc.Input["pid"]; ok { //按pid查找 qry["pid"] = v[0] url += "pid=" + v[0] + "&" pc.Output["SearchPid"] = true pc.Output["SearchValue"] = v[0] } else if v, ok := pc.Input["title"]; ok { //按问题标题查找 url += "title=" + v[0] + "&" pc.Output["SearchTitle"] = true pc.Output["SearchValue"] = v[0] for _, ep := range "+.?$|*^ " { v[0] = strings.Replace(v[0], string(ep), "\\"+string(ep), -1) } qry["title"] = v[0] } else if v, ok := pc.Input["source"]; ok { //按问题来源查找 url += "source=" + v[0] + "&" pc.Output["SearchSource"] = true pc.Output["SearchValue"] = v[0] for _, ep := range "+.?$|*^ " { v[0] = strings.Replace(v[0], string(ep), "\\"+string(ep), -1) } qry["source"] = v[0] } pc.Output["URL"] = url // Page qry["page"] = "1" if v, ok := pc.Input["page"]; ok { //指定页码 qry["page"] = v[0] } if pc.Privilege <= config.PrivilegePU { qry["status"] = "2" //strconv.Itoa(config.StatusAvailable) } problemModel := model.ProblemModel{} count, err := problemModel.Count(qry) if err != nil { pc.Error(err.Error(), 500) return } restweb.Logger.Debug(count) var pageCount = (count-1)/config.ProblemPerPage + 1 page, err := strconv.Atoi(qry["page"]) if err != nil { pc.Error("args error", 400) return } if page > pageCount { pc.Error("args error", 400) return } qry["offset"] = strconv.Itoa((page - 1) * config.ProblemPerPage) //偏移位置 qry["limit"] = strconv.Itoa(config.ProblemPerPage) //每页问题数量 pageData := pc.GetPage(page, pageCount) for k, v := range pageData { pc.Output[k] = v } problemList, err := problemModel.List(qry) if err != nil { pc.Error("post error", 500) return } restweb.Logger.Debug(len(problemList)) solutionModel := &model.SolutionModel{} achieve, _ := solutionModel.Achieve(pc.Uid, config.ModuleP, config.ModuleP) for _, p := range problemList { p.Flag = config.FlagNA for _, i := range achieve { if p.Pid == i { p.Flag = config.FLagAC break } } if p.Flag == config.FlagNA { args := make(map[string]string) args["pid"] = strconv.Itoa(p.Pid) args["module"] = strconv.Itoa(config.ModuleP) args["uid"] = pc.Uid l, _ := solutionModel.List(args) if len(l) > 0 { p.Flag = config.FLagER } } } pc.Output["Problem"] = problemList pc.Output["Privilege"] = pc.Privilege pc.Output["Time"] = restweb.GetTime() pc.Output["Title"] = "Problem List" pc.Output["IsProblem"] = true pc.RenderTemplate("view/layout.tpl", "view/problem_list.tpl") }