当前位置: 首页>>代码示例>>Golang>>正文


Golang ContestModel.Detail方法代码示例

本文整理汇总了Golang中GoOnlineJudge/model.ContestModel.Detail方法的典型用法代码示例。如果您正苦于以下问题:Golang ContestModel.Detail方法的具体用法?Golang ContestModel.Detail怎么用?Golang ContestModel.Detail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GoOnlineJudge/model.ContestModel的用法示例。


在下文中一共展示了ContestModel.Detail方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: InitContest

func (c *Contest) InitContest(Cid string) {
	c.Init()

	cid, err := strconv.Atoi(Cid)
	if err != nil {
		c.Error(err.Error(), 400)
		return
	}
	c.Cid = cid

	contestModel := model.ContestModel{}
	c.ContestDetail, err = contestModel.Detail(cid)
	if err != nil {
		c.Error(err.Error(), 500)
		return
	}

	c.Index = make(map[int]int)
	for k, v := range c.ContestDetail.List {
		c.Index[v] = k
	}
	c.Output["Cid"] = strconv.Itoa(c.Cid)
	c.Output["Title"] = "Contest Detail " + strconv.Itoa(c.Cid)
	c.Output["Contest"] = c.ContestDetail.Title
	c.Output["IsContestDetail"] = true
	c.Output["IsContest"] = true
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:27,代码来源:contest.go

示例2: InitContest

func (this *Contest) InitContest(w http.ResponseWriter, r *http.Request) {
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	cid, err := strconv.Atoi(args["cid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}
	this.Cid = cid

	contestModel := model.ContestModel{}
	this.ContestDetail, err = contestModel.Detail(cid)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	this.Index = make(map[int]int)
	for k, v := range this.ContestDetail.List {
		this.Index[v] = k
	}
	this.Data["Cid"] = strconv.Itoa(this.Cid)
	this.Data["Title"] = "Contest Detail " + strconv.Itoa(this.Cid)
	this.Data["Contest"] = this.ContestDetail.Title
	this.Data["IsContestDetail"] = true
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:27,代码来源:contest.go

示例3: Status

//更改contest状态
//@URL:/admin/contests/(\d+)/status/ @method:POST
func (cc *AdminContest) Status(Cid string) {
	restweb.Logger.Debug("Admin Contest Status")

	cid, err := strconv.Atoi(Cid)
	if err != nil {
		cc.Error("args error", 400)
		return
	}
	contestModel := model.ContestModel{}
	one, _ := contestModel.Detail(cid)
	if one.Creator != cc.Uid {
		cc.Error("privilege error", 400)
		return
	}

	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = contestModel.Status(cid, status)
	if err != nil {
		cc.Error(err.Error(), 500)
		return
	}

	cc.Redirect("/admin/contests", http.StatusFound) //重定向到竞赛列表页
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:33,代码来源:contest.go

示例4: Delete

//删除竞赛
//@URL: /admin/contests/(\d+)/delete/ @method:POST
func (cc *AdminContest) Delete(Cid string) {
	restweb.Logger.Debug("Admin Contest Delete")

	cid, err := strconv.Atoi(Cid)
	if err != nil {
		cc.Error("args error", 400)
		return
	}
	contestModel := model.ContestModel{}
	old, _ := contestModel.Detail(cid)
	if old.Creator != cc.Uid {
		cc.Error("privilege error", 400)
		return
	}

	err = contestModel.Delete(cid)
	if err != nil {
		cc.Error(err.Error(), 400)
		return
	}
	cc.W.WriteHeader(200)
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:24,代码来源:contest.go

示例5: Status

//更改contest状态 url:/admin/contest/status/
func (this *ContestController) Status(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Contest Status")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Change contest status")
		return
	}
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	cid, err := strconv.Atoi(args["cid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	contestModel := model.ContestModel{}
	one, err := contestModel.Detail(cid)

	Type := one.Type

	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = contestModel.Status(cid, status)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	http.Redirect(w, r, "/admin/contest?list/type?"+strings.Title(Type), http.StatusFound) //重定向到竞赛列表页
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:37,代码来源:contest.go

示例6: Update

// 更新竞赛
//@URL:/admin/contests/(\d+)/ @method:POST
func (cc *AdminContest) Update(Cid string) {
	restweb.Logger.Debug("Admin Contest Update")

	cid, err := strconv.Atoi(Cid)
	if err != nil {
		cc.Error("args error", 400)
		return
	}
	contestModel := model.ContestModel{}
	old, _ := contestModel.Detail(cid)
	if old.Creator != cc.Uid {
		cc.Error("privilege error", 400)
		return
	}

	one := cc.contest()

	err = contestModel.Update(cid, one)
	if err != nil {
		cc.Error(err.Error(), 400)
		return
	}
	cc.Redirect("/admin/contests", http.StatusFound)
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:26,代码来源:contest.go

示例7: Edit

// 竞赛编辑页面,url:/admin/contest/edit/
func (this *ContestController) Edit(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Contest Edit")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	cid, err := strconv.Atoi(args["cid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	var one struct {
		*model.Contest
		StartTimeYear   int
		StartTimeMonth  int
		StartTimeDay    int
		StartTimeHour   int
		StartTimeMinute int
		EndTimeYear     int
		EndTimeMonth    int
		EndTimeDay      int
		EndTimeHour     int
		EndTimeMinute   int
		ProblemList     string
		IsPublic        bool
		IsPrivate       bool
		IsPassword      bool
	}
	contestModel := model.ContestModel{}
	one.Contest, err = contestModel.Detail(cid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	start := time.Unix(one.Start, 0).Local()
	one.StartTimeYear = start.Year()
	one.StartTimeMonth = int(start.Month())
	one.StartTimeDay = start.Day()
	one.StartTimeHour = start.Hour()
	one.StartTimeMinute = start.Minute()

	end := time.Unix(one.End, 0).Local()
	one.EndTimeYear = end.Year()
	one.EndTimeMonth = int(end.Month())
	one.EndTimeDay = end.Day()
	one.EndTimeHour = end.Hour()
	one.EndTimeMinute = end.Minute()
	one.ProblemList = ""
	for _, v := range one.List {
		one.ProblemList += strconv.Itoa(v) + ";"
	}
	one.IsPublic = false
	one.IsPrivate = false
	one.IsPassword = false
	switch one.Encrypt {
	case config.EncryptPB:
		one.IsPublic = true
	case config.EncryptPT:
		one.IsPrivate = true
	case config.EncryptPW:
		one.IsPassword = true
	}

	this.Data["Detail"] = one
	Type := one.Type
	this.Data["Title"] = "Admin - " + strings.Title(Type) + " Edit"
	this.Data["Is"+strings.Title(Type)] = true
	this.Data["IsEdit"] = true

	err = this.Execute(w, "view/admin/layout.tpl", "view/admin/contest_edit.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
开发者ID:netyum,项目名称:GoOnlineJudge,代码行数:77,代码来源:contest.go

示例8: requireContest

func requireContest(ctx *restweb.Context) bool {
	url := ctx.R.URL.Path
	if restweb.GetAction(url, 2) == "password" {
		return false
	}
	Cid := restweb.GetAction(url, 1)
	cid, err := strconv.Atoi(Cid)
	if err != nil {
		return true
	}

	contestModel := model.ContestModel{}
	ContestDetail, err := contestModel.Detail(cid)
	if err != nil {
		return true
	}
	prvs := "0" + ctx.GetSession("Privilege")
	prv, err := strconv.Atoi(prvs)
	if err != nil {
		restweb.Logger.Debug(err)
		return true
	}
	Uid := ctx.GetSession("Uid")

	restweb.Logger.Debug(Uid, prv)
	if prv < config.PrivilegeTC {
		if time.Now().Unix() < ContestDetail.Start || ContestDetail.Status == config.StatusReverse {
			info := "The contest has not started yet"
			if ContestDetail.Status == config.StatusReverse {
				info = "No such contest"
			}
			Err400(ctx.W, "Contest", info)
			return true
		} else if ContestDetail.Encrypt == config.EncryptPW {
			if Uid == "" {
				ctx.Redirect("/sess", http.StatusFound)
			} else if ctx.GetSession(Cid+"pass") != ContestDetail.Argument.(string) {
				ctx.Redirect("/contests/"+Cid+"/password", http.StatusFound)
			} else {
				return false
			}
			return true
		} else if ContestDetail.Encrypt == config.EncryptPT {
			if Uid == "" {
				ctx.Redirect("/sess", http.StatusFound)
				return true
			} else {
				userlist := strings.Split(ContestDetail.Argument.(string), "\r\n")
				flag := false
				for _, user := range userlist {
					if user == Uid {
						flag = true
						break
					}
				}
				if flag == false {
					Err400(ctx.W, "Contest",
						"Sorry, the contest is private and you are not granted to participate in the contest.")
					return true
				}
			}
		}
	}
	return false
}
开发者ID:NUOG,项目名称:GoOnlineJudge,代码行数:65,代码来源:filter.go

示例9: Edit

// 竞赛编辑页面,
//@URL:/admin/contests/(\d+)/ @method:GET
func (cc *AdminContest) Edit(Cid string) {
	restweb.Logger.Debug("Admin Contest Edit")

	cid, err := strconv.Atoi(Cid)
	if err != nil {
		cc.Error("args error", 400)
		return
	}

	var one struct {
		*model.Contest
		StartTimeYear   int
		StartTimeMonth  int
		StartTimeDay    int
		StartTimeHour   int
		StartTimeMinute int
		EndTimeYear     int
		EndTimeMonth    int
		EndTimeDay      int
		EndTimeHour     int
		EndTimeMinute   int
		ProblemList     string
		IsPublic        bool
		IsPrivate       bool
		IsPassword      bool
	}
	contestModel := model.ContestModel{}
	one.Contest, err = contestModel.Detail(cid)
	if err != nil {
		cc.Error(err.Error(), 400)
		return
	}

	start := time.Unix(one.Start, 0).Local()
	one.StartTimeYear = start.Year()
	one.StartTimeMonth = int(start.Month())
	one.StartTimeDay = start.Day()
	one.StartTimeHour = start.Hour()
	one.StartTimeMinute = start.Minute()

	end := time.Unix(one.End, 0).Local()
	one.EndTimeYear = end.Year()
	one.EndTimeMonth = int(end.Month())
	one.EndTimeDay = end.Day()
	one.EndTimeHour = end.Hour()
	one.EndTimeMinute = end.Minute()
	one.ProblemList = ""
	for _, v := range one.List {
		one.ProblemList += strconv.Itoa(v) + ";"
	}
	one.IsPublic = false
	one.IsPrivate = false
	one.IsPassword = false
	switch one.Encrypt {
	case config.EncryptPB:
		one.IsPublic = true
	case config.EncryptPT:
		one.IsPrivate = true
	case config.EncryptPW:
		one.IsPassword = true
	}

	cc.Output["Detail"] = one
	cc.Output["Title"] = "Admin - " + "Contest" + " Edit"
	cc.Output["IsContest"] = true
	cc.Output["IsEdit"] = true

	cc.RenderTemplate("view/admin/layout.tpl", "view/admin/contest_edit.tpl")
}
开发者ID:B88000005,项目名称:GoOnlineJudge,代码行数:71,代码来源:contest.go


注:本文中的GoOnlineJudge/model.ContestModel.Detail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。