本文整理汇总了Golang中OnlineJudge/models.Problem.GetByPid方法的典型用法代码示例。如果您正苦于以下问题:Golang Problem.GetByPid方法的具体用法?Golang Problem.GetByPid怎么用?Golang Problem.GetByPid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OnlineJudge/models.Problem
的用法示例。
在下文中一共展示了Problem.GetByPid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Show
// To-do: Show programs solved by the user
func (this *UserController) Show() {
if this.Ctx.Input.Param("0") == "" {
this.Abort("404")
}
user := models.User{Username: this.Ctx.Input.Param("0")}
if user.GetByUsername() {
this.Data["title"] = user.Username
this.Data["userDetails"] = user
log := models.Problemlogs{Uid: user.Uid}
logs, count := log.GetByUid()
problems := make(map[int]models.Problem)
if count == 0 {
this.Data["solvedProblemsExist"] = false
} else {
this.Data["solvedProblemsExist"] = true
for index, element := range logs {
p := models.Problem{Pid: element.Pid}
p.GetByPid()
problems[index] = p
}
}
this.Data["solvedProblems"] = problems
this.Layout = "layout.tpl"
this.TplNames = "user/show.tpl"
this.LayoutSections = make(map[string]string)
this.LayoutSections["HtmlHead"] = ""
this.LayoutSections["Sidebar"] = ""
} else {
this.Abort("404")
}
}
示例2: AddTestCase
func (this *ProblemController) AddTestCase() {
if !this.isLoggedIn() {
this.Redirect("/user/login", 302)
return
}
//Redirect if user doesnt hold editor rights
uid := this.GetSession("id")
user := models.User{Uid: uid.(int)}
if !user.IsEditor() {
this.Redirect("/", 302)
return
}
pid := this.Ctx.Input.Param(":id")
id, _ := strconv.Atoi(pid)
problem := models.Problem{Pid: id}
problem.GetByPid()
this.Data["problem"] = problem
testcases := models.Testcases{Pid: id}
cases, _ := testcases.GetAllByPid()
this.Data["title"] = "Add Test Case"
this.Data["cases"] = cases
this.Layout = "layout.tpl"
this.TplNames = "problem/addtest.tpl"
this.LayoutSections = make(map[string]string)
this.LayoutSections["HtmlHead"] = ""
this.LayoutSections["Sidebar"] = ""
}
示例3: Test
func (this *ProblemController) Test() {
pid := 1
problem := models.Problem{Pid: pid}
problem.GetByPid()
code := this.GetString("code")
lang := this.GetString("language")
stdin := this.GetString("stdin")
output := models.Exec(pid, code, lang, stdin)
js, _ := json.Marshal(output)
this.Data["json"] = string(js)
this.ServeJson()
}
示例4: RunCode
func (this *ProblemController) RunCode() {
if !this.isLoggedIn() {
this.Redirect("/user/login", 302)
return
}
//uid := this.GetSession("id")
pid, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
problem := models.Problem{Pid: pid}
problem.GetByPid()
code := this.GetString("code")
lang := this.GetString("language")
stdin := this.GetString("stdin")
output := models.Exec(pid, code, lang, stdin)
js, _ := json.Marshal(output)
this.Data["json"] = string(js)
this.ServeJson()
}