Beispiel #1
0
func (self *EditTopicHandler) Post() {
	self.TplNames = "edit-topic.html"
	flash := beego.NewFlash()

	tid, _ := self.GetInt(":tid")
	nid, _ := self.GetInt("nodeid")

	if nd, err := model.GetNode(nid); nd != nil && err == nil {

		uid, _ := self.GetSession("userid").(int64)
		tid_title := self.GetString("title")
		tid_content := self.GetString("content")

		if tid_title != "" && tid_content != "" {

			if tp, err := model.GetTopic(tid); tp != nil && err == nil {

				tp.Title = tid_title
				tp.Uid = uid

				//删去用户没再使用的图片
				helper.DelLostImages(tp.Content, tid_content)
				tp.Content = tid_content

				if s, e := helper.GetBannerThumbnail(tid_content); e == nil {
					tp.Attachment = s
				}

				if cat, err := model.GetCategory(nd.Pid); err == nil {
					tp.Category = cat.Title
				}

				if row, err := model.PutTopic(tid, tp); row == 1 && err == nil {
					model.SetRecordforImageOnEdit(tid, uid)
					self.Redirect("/"+strconv.Itoa(int(tid))+"/", 302)
				} else {

					flash.Error("更新话题出现错误:", fmt.Sprint(err))
					flash.Store(&self.Controller)
					return
				}
			} else {

				flash.Error("无法获取根本不存在的话题!")
				flash.Store(&self.Controller)
				return
			}
		} else {

			flash.Error("话题标题或内容为空!")
			flash.Store(&self.Controller)
			return
		}
	} else {
		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
Beispiel #2
0
func (self *NewTopicHandler) Post() {
	self.TplNames = "new-topic.html"

	flash := beego.NewFlash()
	nid, _ := self.GetInt("nodeid")

	nd, err := model.GetNode(nid)
	if err != nil || nid == 0 {

		flash.Error("节点不存在,请创建或指定正确的节点!")
		flash.Store(&self.Controller)
		return
	} else {

		cid := nd.Pid
		uid, _ := self.GetSession("userid").(int64)
		sess_username, _ := self.GetSession("username").(string)
		tid_title := self.GetString("title")
		tid_content := self.GetString("content")

		if tid_title != "" && tid_content != "" {

			tp := new(model.Topic)
			tp.Title = tid_title
			tp.Content = tid_content
			tp.Cid = cid
			tp.Nid = nid
			tp.Uid = uid
			tp.Node = nd.Title
			tp.Author = sess_username
			tp.Created = time.Now()

			if s, e := helper.GetBannerThumbnail(tid_content); e == nil {
				tp.Attachment = s
			}

			if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := helper.GetThumbnails(tid_content); e == nil {
				tp.Thumbnails = thumbnails
				tp.ThumbnailsLarge = thumbnailslarge
				tp.ThumbnailsMedium = thumbnailsmedium
				tp.ThumbnailsSmall = thumbnailssmall
			}

			if cat, err := model.GetCategory(cid); err == nil {
				tp.Category = cat.Title
			}

			nodezmap := &map[string]interface{}{
				"topic_time":         time.Now(),
				"topic_count":        model.GetTopicCountByNid(nid),
				"topic_last_user_id": uid}

			if e := model.UpdateNode(nid, nodezmap); e != nil {
				fmt.Println("NewTopic model.UpdateNode errors:", e)
			}

			if tid, err := model.PostTopic(tp); err == nil {
				model.SetRecordforImageOnPost(tid, uid)
				self.Redirect("/"+strconv.Itoa(int(tid))+"/", 302)
			} else {

				flash.Error(fmt.Sprint(err))
				flash.Store(&self.Controller)
				return
			}
		} else {
			flash.Error("话题标题或内容为空!")
			flash.Store(&self.Controller)
			return
		}
	}
}