Esempio n. 1
0
//@URL: /admin/problems/ @method: GET
func (pc *AdminProblem) List() {
	restweb.Logger.Debug("Admin Problem List")

	problemModel := model.ProblemModel{}
	qry := make(map[string]string)

	qry["page"] = "1"
	if v, ok := pc.Input["page"]; ok { //指定页码
		qry["page"] = v[0]
	}
	count, err := problemModel.Count(qry)
	if err != nil {
		pc.Error(err.Error(), 500)
		return
	}

	restweb.Logger.Debug(count)
	var pageCount = (count-1)/config.ProblemPerPage + 1
	page, err := strconv.Atoi(qry["page"])
	if err != nil {
		pc.Error("args error", 400)
		return
	}
	if page > pageCount {
		pc.Error("args error", 400)
		return
	}

	qry["offset"] = strconv.Itoa((page - 1) * config.ProblemPerPage) //偏移位置
	qry["limit"] = strconv.Itoa(config.ProblemPerPage)               //每页问题数量
	pageData := pc.GetPage(page, pageCount)
	for k, v := range pageData {
		pc.Output[k] = v
	}

	proList, err := problemModel.List(qry)
	if err != nil {
		pc.Error(err.Error(), 400)
		return
	}

	pc.Output["Problem"] = proList
	pc.Output["Title"] = "Admin - Problem List"
	pc.Output["IsProblem"] = true
	pc.Output["IsList"] = true

	pc.RenderTemplate("view/admin/layout.tpl", "view/admin/problem_list.tpl")
}
Esempio n. 2
0
func (this *ProblemController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Problem List")
	this.Init(w, r)

	problemModel := model.ProblemModel{}
	qry := make(map[string]string)
	proList, err := problemModel.List(qry)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}

	this.Data["Problem"] = proList
	this.Data["Title"] = "Admin - Problem List"
	this.Data["IsProblem"] = true
	this.Data["IsList"] = true

	err = this.Execute(w, "view/admin/layout.tpl", "view/admin/problem_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}
Esempio n. 3
0
// 列出特定数量的问题?pid=<pid>&titile=<titile>&source=<source>&page=<page>
//@URL:/problems @method:GET
func (pc *ProblemController) List() {
	restweb.Logger.Debug(pc.R.RemoteAddr + "visit Problem List")

	qry := make(map[string]string)
	url := "/problems?"

	// Search
	if v, ok := pc.Input["pid"]; ok { //按pid查找
		qry["pid"] = v[0]
		url += "pid=" + v[0] + "&"
		pc.Output["SearchPid"] = true
		pc.Output["SearchValue"] = v[0]
	} else if v, ok := pc.Input["title"]; ok { //按问题标题查找
		url += "title=" + v[0] + "&"
		pc.Output["SearchTitle"] = true
		pc.Output["SearchValue"] = v[0]
		for _, ep := range "+.?$|*^ " {
			v[0] = strings.Replace(v[0], string(ep), "\\"+string(ep), -1)
		}
		qry["title"] = v[0]
	} else if v, ok := pc.Input["source"]; ok { //按问题来源查找
		url += "source=" + v[0] + "&"
		pc.Output["SearchSource"] = true
		pc.Output["SearchValue"] = v[0]
		for _, ep := range "+.?$|*^ " {
			v[0] = strings.Replace(v[0], string(ep), "\\"+string(ep), -1)
		}
		qry["source"] = v[0]
	}
	pc.Output["URL"] = url

	// Page
	qry["page"] = "1"
	if v, ok := pc.Input["page"]; ok { //指定页码
		qry["page"] = v[0]
	}

	if pc.Privilege <= config.PrivilegePU {
		qry["status"] = "2" //strconv.Itoa(config.StatusAvailable)
	}

	problemModel := model.ProblemModel{}
	count, err := problemModel.Count(qry)
	if err != nil {
		pc.Error(err.Error(), 500)
		return
	}

	restweb.Logger.Debug(count)
	var pageCount = (count-1)/config.ProblemPerPage + 1
	page, err := strconv.Atoi(qry["page"])
	if err != nil {
		pc.Error("args error", 400)
		return
	}
	if page > pageCount {
		pc.Error("args error", 400)
		return
	}

	qry["offset"] = strconv.Itoa((page - 1) * config.ProblemPerPage) //偏移位置
	qry["limit"] = strconv.Itoa(config.ProblemPerPage)               //每页问题数量
	pageData := pc.GetPage(page, pageCount)
	for k, v := range pageData {
		pc.Output[k] = v
	}

	problemList, err := problemModel.List(qry)
	if err != nil {
		pc.Error("post error", 500)
		return
	}
	restweb.Logger.Debug(len(problemList))

	solutionModel := &model.SolutionModel{}
	achieve, _ := solutionModel.Achieve(pc.Uid, config.ModuleP, config.ModuleP)
	for _, p := range problemList {
		p.Flag = config.FlagNA
		for _, i := range achieve {
			if p.Pid == i {
				p.Flag = config.FLagAC
				break
			}
		}
		if p.Flag == config.FlagNA {
			args := make(map[string]string)
			args["pid"] = strconv.Itoa(p.Pid)
			args["module"] = strconv.Itoa(config.ModuleP)
			args["uid"] = pc.Uid
			l, _ := solutionModel.List(args)
			if len(l) > 0 {
				p.Flag = config.FLagER
			}
		}
	}

	pc.Output["Problem"] = problemList
	pc.Output["Privilege"] = pc.Privilege
	pc.Output["Time"] = restweb.GetTime()
	pc.Output["Title"] = "Problem List"
	pc.Output["IsProblem"] = true
	pc.RenderTemplate("view/layout.tpl", "view/problem_list.tpl")
}
Esempio n. 4
0
// 列出特定数量的问题,URL,/problem?list/pid?<pid>/titile?<titile>/source?<source>/page?<page>
func (this *ProblemController) List(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug(r.RemoteAddr + "visit Problem List")
	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	url := "/problem?list"

	// Search
	if v, ok := args["pid"]; ok { //按pid查找
		url += "/pid?" + v
		this.Data["SearchPid"] = true
		this.Data["SearchValue"] = v
	}
	if v, ok := args["title"]; ok { //按问题标题查找
		url += "/title?" + v
		this.Data["SearchTitle"] = true
		this.Data["SearchValue"] = v
	}
	if v, ok := args["source"]; ok { //按问题来源查找
		v = strings.Replace(v, "%20", " ", -1)
		args["source"] = v
		url += "/source?" + v
		this.Data["SearchSource"] = true
		this.Data["SearchValue"] = v
	}
	this.Data["URL"] = url

	// Page
	if _, ok := args["page"]; !ok { //指定页码
		args["page"] = "1"
	}

	problemModel := model.ProblemModel{}
	count, err := problemModel.Count(args)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	var pageCount = (count-1)/config.ProblemPerPage + 1
	page, err := strconv.Atoi(args["page"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}
	if page > pageCount {
		http.Error(w, "args error", 400)
		return
	}

	args["offset"] = strconv.Itoa((page - 1) * config.ProblemPerPage) //偏移位置
	args["limit"] = strconv.Itoa(config.ProblemPerPage)               //每页问题数量
	pageData := this.GetPage(page, pageCount)
	for k, v := range pageData {
		this.Data[k] = v
	}

	problemList, err := problemModel.List(args)
	if err != nil {
		http.Error(w, "post error", 500)
		return
	}

	this.Data["Problem"] = problemList
	this.Data["Privilege"] = this.Privilege
	this.Data["Time"] = this.GetTime()
	this.Data["Title"] = "Problem List"
	this.Data["IsProblem"] = true
	err = this.Execute(w, "view/layout.tpl", "view/problem_list.tpl")
	if err != nil {
		http.Error(w, "tpl error", 500)
		return
	}
}