Exemplo n.º 1
0
func (this *ProblemController) SaveTestCase() {
	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)

	timeout, _ := strconv.Atoi(this.GetString("timeout"))
	//remove string replace
	input := strings.Replace(this.GetString("input"), "\r", "", -1)
	output := strings.Replace(this.GetString("output"), "\r", "", -1)
	testcase := models.Testcases{
		Pid: id,
		//Input:   this.GetString("input"),
		//Output:  this.GetString("output"),
		Timeout: timeout,
	}
	testcase.Input = input
	testcase.Output = output
	done := testcase.Create()
	if done == true {
		this.Redirect("/problem/"+pid, 302)
	}
	this.Redirect("/problem/"+pid+"/addtest", 302)
}
Exemplo n.º 2
0
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"] = ""

}