Exemple #1
0
func (c Article) DoPush(topic *model.Topic) revel.Result {
	//topic.Body = template.HTML(c.Request.PostFormValue("editormd-html-code"))
	uName, ok := c.Session["user"]
	if !ok {
		c.Session["preUrl"] = "/push"
		c.Flash.Error("亲,登录之后才能发布哦!")
		return c.Redirect("/login")
	}
	topic.UName = uName
	dao, err := model.NewDao()
	topic.Status = 1
	//	if topic.Tag == 4 {
	//		topic.Status = 0
	//	}
	defer dao.Close()
	id, err := dao.InserTopic(topic)
	if err != nil {
		revel.ERROR.Printf("Unable to save topic: %v error %v", topic, err)
		c.Response.Status = 500
		return c.RenderError(err)
	}
	err = utils.UploadString(c.Request.PostFormValue("editormd-html-code"), fmt.Sprintf("%s.html", id))
	err = utils.UploadString(c.Request.PostFormValue("Body"), fmt.Sprintf("%s_code.html", id))
	return c.Redirect("/show/%s", id)
}
Exemple #2
0
func (c Article) DoEdit(topic *model.Topic) revel.Result {
	//topic.Body = template.HTML(c.Request.PostFormValue("editormd-html-code"))
	_, ok := c.Session["user"]
	if !ok {
		c.Session["preUrl"] = fmt.Sprintf("/edit/%s", topic.Id)
		c.Flash.Error("亲,登录之后才能发布哦!")
		return c.Redirect("/login")
	}
	dao, err := model.NewDao()
	defer dao.Close()
	oldTopic := dao.FindTopicById(c.Request.PostFormValue("Id"))
	if oldTopic == nil {
		return c.Redirect("/")
	}
	oldTopic.Title = topic.Title
	oldTopic.Tag = topic.Tag
	//	if topic.Tag == 4 {
	//		oldTopic.Status = 0
	//	}
	id, err := dao.EditTopic(oldTopic)
	if err != nil {
		revel.ERROR.Printf("Unable to save topic: %v error %v", topic, err)
		c.Response.Status = 500
		return c.RenderError(err)
	}
	revel.INFO.Printf("The id: %s", id)
	utils.DeleteFile(id)
	err = utils.UploadString(c.Request.PostFormValue("editormd-html-code"), fmt.Sprintf("%s.html", oldTopic.Id.Hex()))
	err = utils.UploadString(c.Request.PostFormValue("Body"), fmt.Sprintf("%s_code.html", id))
	return c.Redirect("/show/%s", id)
}