Ejemplo n.º 1
0
func (c WBlog) Putup(blog *models.Blog) revel.Result {
	blog.Title = strings.TrimSpace(blog.Title)
	blog.Email = strings.TrimSpace(blog.Email)
	blog.Subject = strings.TrimSpace(blog.Subject)
	blog.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		fmt.Println(c.Validation)
		return c.Redirect(App.WBlog)
	}
	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	err = dao.CreateBlog(blog)
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	// newEmail := new(models.EmailObj)
	// newEmail.Email = blog.Email
	// dao.InsertEmail(newEmail)
	return c.Redirect(App.Index)
}
Ejemplo n.º 2
0
func (c App) Index() revel.Result {
	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	//dao := models.NewDao(c.MongoSession)
	blogs := dao.FindBlogs()
	now := time.Now().Add(-1 * time.Hour)
	recentCnt := dao.FindBlogsByDate(now)
	return c.Render(blogs, recentCnt)
}