コード例 #1
0
ファイル: view.go プロジェクト: eramus/discuss
func addForm(r *http.Request, d_id uint64, parts []string) (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	labels, uris := shared.GetDiscussionBreadcrumbs(d_id, false)
	labels, uris = append(labels, "Add Topic"), append(uris, "")
	body.Breadcrumbs = &shared.Breadcrumbs{labels, uris}

	f := new(Form)
	f.Uri = strings.Join(parts, "/")
	f.DId = d_id

	if r.Method == "POST" {
		f.Title = r.FormValue("title")
		f.Post = r.FormValue("post")

	}
	body.ContentData = f
	body.Title = "Add Topic"
	tpl, _ = addTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Add Topic"))
	return
}
コード例 #2
0
ファイル: controller.go プロジェクト: eramus/discuss
func ViewDiscussion(r *http.Request, sess *sessions.Session) (body *shared.Body, tpl *template.Template, redirect string) {
	//	log.Println("route: view discussion")
	var u_id uint64
	if _, ok := sess.Values["id"]; ok {
		u_id = sess.Values["id"].(uint64)
	}
	// figure out where we are
	parts := strings.Split(html.EscapeString(r.URL.Path[1:]), "/")
	if len(parts) < 2 {
		redirect = "/"
		return
	}
	parts = parts[1:]
	var uri = strings.Join(parts, "/")
	id, err := getId(uri)
	if err != nil {
		// uhh
		redirect = "/"
	} else if id > 0 {
		// show current topics -- w pagination
		/*		if !shared.CanDo(u_id, id, VIEW) {
				log.Println("no permission")
				redirect = "/"
			} else {*/
		ts, _ := topics(id)
		key := fmt.Sprintf("discussion:%d:title", id)
		te, rerr := shared.RedisClient.Get(key)
		if rerr != nil {
			log.Println("redis err:", rerr)
			redirect = "/"
		} else {
			labels, uris := shared.GetDiscussionBreadcrumbs(id, true)
			key := fmt.Sprintf("user:%d:joined", u_id)
			im, rerr := shared.RedisClient.Sismember(key, id)
			if rerr != nil {
				log.Println("redis err:", rerr)
				redirect = "/"
			}
			if im {
				labels, uris = append(labels, "Unsubscribe"), append(uris, "/leave/"+uri)
			} else {
				labels, uris = append(labels, "Subscribe"), append(uris, "/join/"+uri)
			}
			body = &shared.Body{
				Breadcrumbs: &shared.Breadcrumbs{labels, uris},
				ContentData: &List{
					Id:     id,
					Uri:    uri,
					Topics: ts,
				},
				Title: te.String(),
			}
			tpl, _ = listTpls.Clone()
			tpl.Parse(shared.GetPageTitle(te.String()))
		}
		//		}
	} else {
		// want to add?
		body, tpl = addForm(r)
		if err != nil {
			log.Println("no page:", err)
		}
	}
	return
}