示例#1
0
// get function
func (self *GetOldDataWaitress) Get(w http.ResponseWriter, r *http.Request, c appengine.Context) {
	// Put a test data
	// Delete this for the real gae runtime
	// testArticle := &Article{
	// 	Title:      "Old Data",
	// 	Content:    []byte("Now you see old dta"),
	// 	CreateTime: time.Now(),
	// }
	// datastore.Put(c, datastore.NewIncompleteKey(c, "article", nil), testArticle)

	// * Get all old article.
	articles := make([]Article, 0)
	q := datastore.NewQuery("article").Order("-CreateTime")
	q.GetAll(c, &articles)

	// * Add to current datastore.
	for _, article := range articles {
		articleModel := &M.Article{
			Title:      article.Title,
			Content:    string(article.Content),
			CreateTime: article.CreateTime,
			ID:         "",
		}
		err := ds.AddArticle(articleModel, c)
		oops(err, w)
	}
	printSuccessPage(self.GetApp(), w, r, "数据复制成功")
}
示例#2
0
// post function
func (self *AddArticleWaitress) Post(w http.ResponseWriter, r *http.Request, c appengine.Context) {

	// get info from page, and build a modle
	r.ParseForm()
	article := &M.Article{
		Title:      r.Form.Get("title"),
		Content:    r.Form.Get("content"),
		CreateTime: time.Now(),
		ID:         "",
	}
	// c.Warningf("article is: ", article)
	// save to datastore
	err := ds.AddArticle(article, c)
	oops(err, w)
	printSuccessPage(self.GetApp(), w, r, "添加成功!")

	return
}