Esempio n. 1
0
// 插入比赛
//@URL:/admin/contests/ @method:POST
func (cc *AdminContest) Insert() {
	restweb.Logger.Debug("Admin Contest Insert")

	one := cc.contest()
	contestModel := model.ContestModel{}
	err := contestModel.Insert(one)
	if err != nil {
		cc.Error(err.Error(), 500)
		return
	}

	cc.Redirect("/admin/contests", http.StatusFound) //重定向到竞赛列表页
}
Esempio n. 2
0
// 插入比赛 url:/admin/contest?insert/type?<contest,exercise>
func (this *ContestController) Insert(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin Contest Insert")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to Insert contest")
		return
	}

	this.Init(w, r)

	args := this.ParseURL(r.URL.String())
	Type := args["type"]

	one := model.Contest{}

	one.Title = r.FormValue("title")
	one.Type = Type
	year, err := strconv.Atoi(r.FormValue("startTimeYear"))
	month, err := strconv.Atoi(r.FormValue("startTimeMonth"))
	day, err := strconv.Atoi(r.FormValue("startTimeDay"))
	hour, err := strconv.Atoi(r.FormValue("startTimeHour"))
	min, err := strconv.Atoi(r.FormValue("startTimeMinute"))
	start := time.Date(year, time.Month(month), day, hour, min, 0, 0, time.Local)
	one.Start = start.Unix()

	year, err = strconv.Atoi(r.FormValue("endTimeYear"))
	month, err = strconv.Atoi(r.FormValue("endTimeMonth"))
	day, err = strconv.Atoi(r.FormValue("endTimeDay"))
	hour, err = strconv.Atoi(r.FormValue("endTimeHour"))
	min, err = strconv.Atoi(r.FormValue("endTimeMinute"))
	end := time.Date(year, time.Month(month), day, hour, min, 0, 0, time.Local)
	one.End = end.Unix()

	if start.After(end) {
		http.Error(w, "args error", 400)
		return
	}

	switch r.FormValue("type") {
	case "public":
		one.Encrypt = config.EncryptPB
	case "private":
		one.Encrypt = config.EncryptPT
		argument := r.FormValue("userlist")
		var cr rune = 13
		crStr := string(cr)
		argument = strings.Trim(argument, crStr)
		argument = strings.Trim(argument, "/r/n")
		argument = strings.Replace(argument, "/r/n", "", -1)
		argument = strings.Replace(argument, crStr, "/n", -1)
		one.Argument = argument
	case "password":
		one.Encrypt = config.EncryptPW
		one.Argument = r.FormValue("password")
	default:
		http.Error(w, "args error", 400)
		return
	}

	problemString := r.FormValue("problemList")
	problemString = strings.Trim(problemString, " ")
	problemString = strings.Trim(problemString, ";")
	problemList := strings.Split(problemString, ";")
	var list []int
	for _, v := range problemList {
		pid, err := strconv.Atoi(v)
		if err != nil {
			http.Error(w, "conv error", 400)
			return
		}
		list = append(list, pid)
	}
	one.List = list //problemList 建议检查下problem是否存在,存在的将其在普通列表中不可见

	contestModel := model.ContestModel{}
	err = contestModel.Insert(one)
	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	http.Redirect(w, r, "/admin/contest?list/type?"+Type, http.StatusFound) //重定向到竞赛列表页
}