示例#1
0
//@URL: /admin/problems/(\d+)/ @method: POST
func (pc *AdminProblem) Update(Pid string) {
	restweb.Logger.Debug("Admin Problem Update")

	if pc.Privilege != config.PrivilegeAD {
		pc.Err400("Warning", "Error Privilege to Update problem")
		return
	}

	pid, err := strconv.Atoi(Pid)
	if err != nil {
		pc.Error("args error", 400)
		return
	}
	one := pc.problem()

	problemModel := model.ProblemModel{}
	err = problemModel.Update(pid, one)
	if err != nil {
		pc.Error(err.Error(), 500)
		return
	}
	createfile(config.Datapath+strconv.Itoa(pid), "sample.in", one.In)
	createfile(config.Datapath+strconv.Itoa(pid), "sample.out", one.Out)

	pc.Redirect("/problems/"+strconv.Itoa(pid), http.StatusFound)
}
示例#2
0
func (this *ProblemController) Update(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Problem Update")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Update problem")
		return
	}

	this.Init(w, r)
	if this.Privilege != config.PrivilegeAD {
		this.Err400(w, r, "Warning", "Error Privilege to Update problem")
		return
	}

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

	one := model.Problem{}
	one.Title = r.FormValue("title")
	time, err := strconv.Atoi(r.FormValue("time"))
	if err != nil {
		http.Error(w, "The value 'Time' is neither too short nor too large", 500)
		return
	}
	one.Time = time
	memory, err := strconv.Atoi(r.FormValue("memory"))
	if err != nil {
		http.Error(w, "The value 'memory' is neither too short nor too large", 500)
		return
	}
	one.Memory = memory
	if special := r.FormValue("special"); special == "" {
		one.Special = 0
	} else {
		one.Special = 1
	}

	in := r.FormValue("in")
	out := r.FormValue("out")

	one.Description = template.HTML(r.FormValue("description"))
	one.Input = template.HTML(r.FormValue("input"))
	one.Output = template.HTML(r.FormValue("output"))
	one.In = in
	one.Out = out
	one.Source = r.FormValue("source")
	one.Hint = r.FormValue("hint")

	createfile(config.Datapath+args["pid"], "sample.in", in)
	createfile(config.Datapath+args["pid"], "sample.out", out)

	problemModel := model.ProblemModel{}
	err = problemModel.Update(pid, one)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	http.Redirect(w, r, "/admin/problem?detail/pid?"+strconv.Itoa(pid), http.StatusFound)
}