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) }
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) }
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) }
func (this *PostListRouter) setTopics(topics *[]models.Topic) { models.FindTopics(topics) this.Data["Topics"] = *topics }
func (this *PostAdminRouter) GetForm(create bool) post.PostAdminForm { form := post.PostAdminForm{Create: create} models.FindTopics(&form.Topics) return form }