コード例 #1
0
ファイル: view.go プロジェクト: eramus/discuss
func addForm(r *http.Request, t_id, p_id uint64) (body *shared.Body, tpl *template.Template) {
	t, rerr := shared.RedisClient.Get(fmt.Sprintf("topic:%d:title", t_id))
	if rerr != nil {
		return
	}
	labels, uris := shared.GetTopicBreadcrumbs(t_id)
	if p_id > 0 {
		labels, uris = append(labels, t.String()), append(uris, fmt.Sprintf("/topic/%d#%d", t_id, p_id))
	} else {
		labels, uris = append(labels, t.String()), append(uris, fmt.Sprintf("/topic/%d", t_id))
	}
	labels, uris = append(labels, "Add Post"), append(uris, "")

	body = new(shared.Body)
	f := new(Form)
	f.TId = t_id
	if p_id > 0 {
		f.PId = p_id
	}
	if r.Method == "POST" {
		f.Post = r.FormValue("post")
	}
	body.Breadcrumbs = &shared.Breadcrumbs{labels, uris}
	body.ContentData = f
	body.Title = "Add Post"
	tpl, _ = addTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Add Post"))
	return
}
コード例 #2
0
ファイル: controller.go プロジェクト: eramus/discuss
func ViewTopic(r *http.Request, sess *sessions.Session) (body *shared.Body, tpl *template.Template, redirect string) {
	//	log.Println("route: view topic")
	parts := strings.Split(html.EscapeString(r.URL.Path[1:]), "/")
	if len(parts) < 2 {
		redirect = "/"
		return
	}
	id, err := strconv.ParseUint(parts[1], 10, 64)
	if err != nil {
		redirect = "/"
		return
	}
	if !exists(id) {
		redirect = "/"
		return
	}
	t, err := getById(id)
	body = new(shared.Body)
	labels, uris := shared.GetTopicBreadcrumbs(t.Id)
	labels, uris = append(labels, t.Title), append(uris, "")
	body.Breadcrumbs = &shared.Breadcrumbs{labels, uris}
	body.ContentData = t
	body.Title = t.Title
	go addView(t.DId, t.Id)
	tpl, _ = viewTpls.Clone()
	tpl.Parse(shared.GetPageTitle(t.Title))
	return
}