예제 #1
0
파일: edit.go 프로젝트: wcreate/lawoto
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
	}
}
예제 #2
0
파일: new.go 프로젝트: wcreate/lawoto
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
	}

}