Exemple #1
0
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)
}
Exemple #2
0
//New Comment
func (this *SinglePost) Post() {
	if this.CheckActiveRedirect() {
		return
	}

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

	var redir bool

	defer func() {
		if !redir {
			var comments []*models.Comment
			this.loadComments(&postMd, &comments)
		}
	}()

	form := post.CommentForm{}
	if !this.ValidFormSets(&form) {
		return
	}

	comment := models.Comment{}
	if err := form.SaveComment(&comment, &this.User, &postMd); err == nil {
		post.FilterCommentMentions(&this.User, &postMd, &comment)
		this.JsStorage("deleteKey", "post/comment")
		this.Redirect(postMd.Link(), 302)
		redir = true

		post.PostReplysCount(&postMd)
	}
	this.Render("post/post.html", this.Data)
}
Exemple #3
0
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)
}
Exemple #4
0
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)
}