示例#1
0
文件: post.go 项目: trigrass2/wego
func (this *PostRouter) Post() {
	if this.CheckActiveRedirect() {
		return
	}

	var postMd models.Post
	if this.loadPost(&postMd, &this.User) {
		return
	}

	if !postMd.CanEdit {
		this.FlashRedirect(postMd.Path(), 302, "CanNotEditPost")
	}

	form := post.PostForm{}
	form.SetFromPost(&postMd)
	models.FindTopics(&form.Topics)
	if !this.ValidFormSets(&form) {
		return
	}

	if err := form.UpdatePost(&postMd, &this.User); err == nil {
		this.JsStorage("deleteKey", "post/edit")
		this.Redirect(postMd.Link())
		return
	}
	this.Render("post/edit.html", this.Data)
}
示例#2
0
文件: post.go 项目: trigrass2/wego
func (this *NewPost) Post() error {
	if this.CheckActiveRedirect() {
		return nil
	}

	var err error
	form := post.PostForm{Locale: this.Locale}
	topicSlug := this.GetString("topic")
	if len(topicSlug) > 0 {
		topic, err := models.GetTopicBySlug(topicSlug)
		if err == nil {
			form.Category = topic.CategoryId
			form.Topic = topic.Id
			this.Data["Topic"] = topic
		} else {
			log.Error("Can not find topic by slug:", topicSlug)
		}
	} else {
		topicId, err := this.GetInt("Topic")
		if err == nil {
			topic, err := models.GetTopicById(topicId)
			if err == nil {
				form.Category = topic.CategoryId
				form.Topic = topic.Id
				this.Data["Topic"] = topic
			} else {
				log.Error("Can not find topic by id:", topicId)
			}
		} else {
			log.Error("Parse param Topic from request failed", err)
		}
	}
	if categorySlug := this.GetString("category"); categorySlug != "" {
		log.Debug("Find category slug:", categorySlug)
		category, err := models.GetCategoryBySlug(categorySlug)
		if err != nil {
			log.Error("Get category error", err)
		}
		this.Data["Category"] = &category
	}
	err = models.FindTopics(&form.Topics)
	if err != nil {
		return err
	}
	if !this.ValidFormSets(&form) {
		this.Redirect("/new")
		return nil
	}

	var post models.Post
	if err := form.SavePost(&post, &this.User); err == nil {
		this.JsStorage("deleteKey", "post/new")
		this.Redirect(post.Link())
		return nil
	}
	return this.Render("post/new.html", this.Data)
}
示例#3
0
文件: post.go 项目: trigrass2/wego
func (this *EditPost) Get() {
	if this.CheckActiveRedirect() {
		return
	}

	var postMd models.Post
	if this.loadPost(&postMd, &this.User) {
		return
	}

	if !postMd.CanEdit {
		this.Redirect(postMd.Link())
		return
	}
	form := post.PostForm{}
	form.SetFromPost(&postMd)
	models.FindTopics(&form.Topics)
	this.SetFormSets(&form)
	this.Render("post/edit.html", this.Data)
}
示例#4
0
文件: post.go 项目: trigrass2/wego
func (this *PostListRouter) setTopics(topics *[]models.Topic) {
	models.FindTopics(topics)
	this.Data["Topics"] = *topics
}
示例#5
0
func (this *PostAdminRouter) GetForm(create bool) post.PostAdminForm {
	form := post.PostAdminForm{Create: create}
	models.FindTopics(&form.Topics)
	return form
}