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

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

	problemModel := model.ProblemModel{}
	one, err := problemModel.Detail(pid)
	if err != nil {
		pc.Error(err.Error(), 400)
		return
	}
	pc.Output["Detail"] = one
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	case config.StatusReverse:
		status = config.StatusAvailable
	}
	err = problemModel.Status(pid, status)
	if err != nil {
		pc.Error(err.Error(), 500)
		return
	}

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

	this.Init(w, r)

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

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

	problemModel := model.ProblemModel{}
	one, err := problemModel.Detail(pid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	this.Data["Detail"] = one
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	case config.StatusReverse:
		status = config.StatusAvailable
	}
	err = problemModel.Status(pid, status)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	http.Redirect(w, r, "/admin/problem?list", http.StatusFound)
}