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

	form := post.PostForm{Locale: this.Locale}
	topicSlug := this.GetString("topic")
	if len(topicSlug) > 0 {
		topic, err := models.GetTopicBySlug(topicSlug)
		if err != nil {
			this.Redirect(setting.AppUrl)
			return nil
		}

		form.Topic = topic.Id
		form.Category = topic.CategoryId

		err = models.FindTopicsByCategoryId(&form.Topics, topic.CategoryId)
		if err != nil {
			this.Redirect(setting.AppUrl)
			return nil
		}

		this.Data["Topic"] = topic
	} else {
		catSlug := this.GetString("category")
		if len(catSlug) > 0 {
			category, err := models.GetCategoryBySlug(catSlug)
			if err != nil {
				return err
			}

			form.Category = category.Id
			err = models.FindTopicsByCategoryId(&form.Topics, category.Id)
			if err != nil {
				return err
			}
			this.Data["Category"] = category
		} else {
			this.Redirect(setting.AppUrl)
			return nil
		}
	}

	this.SetFormSets(&form)
	return this.Render("post/new.html", this.Data)
}
示例#2
0
文件: post.go 项目: trigrass2/wego
//Get all the topics of the category
func (this *PostListRouter) setTopicsOfCategory(topics *[]models.Topic, category *models.Category) {
	models.FindTopicsByCategoryId(topics, category.Id)
	this.Data["TopicsOfCategory"] = *topics
}