Beispiel #1
0
func (self *EditAnswerController) Post() {
	self.TplNames = "q/edit-answer.html"
	self.LayoutSections["Heads"] = "q/head.html"
	self.LayoutSections["Scripts"] = "q/scripts.html"

	flash := beego.NewFlash()

	aid, _ := self.GetInt64(":aid")

	a := &models.Reply{Id: aid}
	if err := a.Read(); err == orm.ErrNoRows {
		flash.Error("无法获取根本不存在的答案!")
		flash.Store(&self.Controller)
		return
	}

	uid, _ := self.GetSession("userid").(int64)
	role, _ := self.GetSession("userrole").(int64)

	if !isAllow(a, uid, aid, role) {
		//没有权限执行该操作则直接跳转到登录页面
		self.Redirect("/u/signin/", 302)
		return
	}

	q := &models.Question{Id: a.Pid}
	if err := q.ReadOneOnly("Title", "Content"); err == orm.ErrNoRows {
		flash.Error("对应的问题已删除。")
		flash.Store(&self.Controller)
		return
	}

	self.Data["q"] = *q
	self.Data["answer"] = *a
	aid_content := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))

	if aid_content == "" {
		flash.Error("答案内容为空!")
		flash.Store(&self.Controller)
		return
	}

	// 删去用户没再使用的图片
	utils.DelLostImages(a.Content, aid_content)
	a.Content = aid_content

	if s, e := utils.GetBannerThumbnail(aid_content); e == nil {
		a.Attachment = s
	}

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

	a.Updated = time.Now()
	if row, err := a.Update(); row == 1 {
		// model.SetRecordforImageOnEdit(int64(aid), anz.Uid)
		self.Redirect("/q/"+strconv.Itoa(int(a.Pid))+"/#a-"+strconv.Itoa(int(aid)), 302)
	} else {
		flash.Error("更新答案出现错误:", fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
Beispiel #2
0
func (self *EditQuestionController) Post() {
	self.setTemplate()

	flash := beego.NewFlash()

	qid, _ := self.GetInt64(":qid")
	q := &models.Question{Id: qid}
	if err := q.Read(); err == orm.ErrNoRows {
		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}

	uid, _ := self.GetSession("userid").(int64)
	role, _ := self.GetSession("userrole").(int64)

	if !isAllow(q, uid, qid, role) {
		// 没有权限执行该操作则直接跳转到登录页面
		self.Redirect("/u/signin/", 302)
		return
	}

	self.Data["question"] = *q

	qid_title := template.HTMLEscapeString(strings.TrimSpace(self.GetString("title")))
	qid_content := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))
	tags := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("tags"))))

	if qid_title == "" {
		flash.Error("问题标题为空!")
		flash.Store(&self.Controller)
		return
	}

	if qid_content == "" {
		flash.Error("问题内容为空!")
		flash.Store(&self.Controller)
		return
	}

	if tags == "" {
		flash.Error("尚未设置标签,请设定正确的标签!")
		flash.Store(&self.Controller)
		return
	}

	q.Title = qid_title
	// 删去用户没再使用的图片
	utils.DelLostImages(q.Content, qid_content)
	q.Content = qid_content

	if s, e := utils.GetBannerThumbnail(qid_content); e == nil {
		q.Attachment = s
	}

	if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := utils.GetThumbnails(qid_content); e == nil {
		q.Thumbnails = thumbnails
		q.ThumbnailsLarge = thumbnailslarge
		q.ThumbnailsMedium = thumbnailsmedium
		q.ThumbnailsSmall = thumbnailssmall
	}
	/*
		if cat, err := model.GetCategory(nd.Pid); err == nil {
			qs.Category = cat.Title
		}
	*/

	q.Tags = tags
	q.Updated = time.Now()

	if row, err := q.Update("Title", "Content", "Updated", "Tags"); row == 1 {
		//model.SetRecordforImageOnEdit(int64(qid), qs.Uid)
		self.Redirect("/q/"+strconv.Itoa(int(qid))+"/", 302)
	} else {
		flash.Error("更新问题出现错误:", fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}
}
Beispiel #3
0
func (self *NewQuestionController) Post() {
	self.TplNames = "q/new.html"
	self.LayoutSections["Heads"] = "q/head.html"
	self.LayoutSections["Scripts"] = "q/scripts.html"

	flash := beego.NewFlash()
	tags := template.HTMLEscapeString(strings.TrimSpace(strings.ToLower(self.GetString("tags"))))

	if tags == "" {
		flash.Error("尚未设置标签,请设定正确的标签!")
		flash.Store(&self.Controller)
		return
	}

	uid, _ := self.GetSession("userid").(int64)
	sess_username, _ := self.GetSession("username").(string)
	qid_title := template.HTMLEscapeString(strings.TrimSpace(self.GetString("title")))
	qid_content := template.HTMLEscapeString(strings.TrimSpace(self.GetString("content")))

	if qid_title == "" {
		flash.Error("问题标题为空!")
		flash.Store(&self.Controller)
		return
	}

	if qid_content == "" {
		flash.Error("问题内容为空!")
		flash.Store(&self.Controller)
		return
	}

	qs := new(models.Question)
	qs.Title = qid_title
	qs.Tags = tags
	qs.Content = qid_content
	qs.Uid = uid
	qs.Author = sess_username
	qs.Created = time.Now()
	qs.Updated = qs.Created
	qs.ReplyTime = qs.Created

	if s, e := utils.GetBannerThumbnail(qid_content); e == nil {
		qs.Attachment = s
	}

	if thumbnails, thumbnailslarge, thumbnailsmedium, thumbnailssmall, e := utils.GetThumbnails(qid_content); e == nil {
		qs.Thumbnails = thumbnails
		qs.ThumbnailsLarge = thumbnailslarge
		qs.ThumbnailsMedium = thumbnailsmedium
		qs.ThumbnailsSmall = thumbnailssmall
	}

	if err := qs.Insert(); err == nil {
		// TODO
		//models.SetRecordforImageOnPost(qts.Id, uid)
		self.Redirect("/q/"+strconv.Itoa(int(qs.Id))+"/", 302)
	} else {
		flash.Error(fmt.Sprint(err))
		flash.Store(&self.Controller)
		return
	}

}