Example #1
0
func addmember(w http.ResponseWriter, r *http.Request) {
	id, _ := strconv.Atoi(r.FormValue("id"))
	name := template.HTMLEscapeString(r.FormValue("name"))
	url := fmt.Sprintf("/view?id=%d", id)

	c := appengine.NewContext(r)

	// メンバーを追加
	var member model.Member
	member.Id = id
	member.Name = name
	if err := member.Add(c); err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}

	// 詳細画面にリダイレクト
	http.Redirect(w, r, url, http.StatusFound)
}
Example #2
0
func batchinsert(w http.ResponseWriter, r *http.Request) {
	var newScore model.Score

	c := appengine.NewContext(r)

	no, _ := strconv.Atoi(r.FormValue("no"))
	name := template.HTMLEscapeString(r.FormValue("name"))
	japanese, _ := strconv.Atoi(r.FormValue("japanese"))
	math, _ := strconv.Atoi(r.FormValue("math"))
	english, _ := strconv.Atoi(r.FormValue("english"))

	// データを生成
	newScore.Set(no, name, japanese, math, english)

	// データを登録
	if err := newScore.AddScore(c); err != nil {
		systemError(w, err)
		return
	}

}
Example #3
0
func code(file string, arg ...interface{}) (string, os.Error) {
	text := contents(file)
	var command string
	switch len(arg) {
	case 0:
		// text is already whole file.
		command = fmt.Sprintf("code %q", file)
	case 1:
		command = fmt.Sprintf("code %q %s", file, format(arg[0]))
		text = oneLine(file, text, arg[0])
	case 2:
		command = fmt.Sprintf("code %q %s %s", file, format(arg[0]), format(arg[1]))
		text = multipleLines(file, text, arg[0], arg[1])
	default:
		return "", fmt.Errorf("incorrect code invocation: code %q %q", file, arg)
	}
	// Replace tabs by spaces, which work better in HTML.
	text = strings.Replace(text, "\t", "    ", -1)
	// Escape the program text for HTML.
	text = template.HTMLEscapeString(text)
	// Include the command as a comment.
	text = fmt.Sprintf("<pre><!--{{%s}}\n-->%s</pre>", command, text)
	return text, nil
}
Example #4
0
func add(w http.ResponseWriter, r *http.Request) {
	var newScore model.Score

	c := appengine.NewContext(r)

	// パラメータチェック(エラーは無視)
	no, _ := strconv.Atoi(r.FormValue("no"))
	name := template.HTMLEscapeString(r.FormValue("name"))
	japanese, _ := strconv.Atoi(r.FormValue("japanese"))
	math, _ := strconv.Atoi(r.FormValue("math"))
	english, _ := strconv.Atoi(r.FormValue("english"))

	// データを生成
	newScore.Set(no, name, japanese, math, english)

	// データを登録
	if err := newScore.AddScore(c); err != nil {
		systemError(w, err)
		return
	}

	// トップページにリダイレクト
	http.Redirect(w, r, "/", http.StatusSeeOther)
}
Example #5
0
func (s status) XML(b *bytes.Buffer) {
	b.WriteString(fmt.Sprintf("<status>HTTP/1.1 %d %s</status>", s, template.HTMLEscapeString(http.StatusText(int(s)))))
}
Example #6
0
func (h *href) XML(b *bytes.Buffer) {
	b.WriteString("<href>" + template.HTMLEscapeString((*url.URL)(h).String()) + "</href>")
}
Example #7
0
// helpers
func epochToXMLTime(sec int64) string {
	return template.HTMLEscapeString(time.SecondsToUTC(sec).Format(time.RFC3339))
}