Esempio n. 1
0
func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	if post.User == nil {
		post.User = &models.User{}
	}
	post.User.Id = form.User

	if post.LastReply == nil {
		post.LastReply = &models.User{}
	}
	post.LastReply.Id = form.LastReply

	if post.LastAuthor == nil {
		post.LastAuthor = &models.User{}
	}
	post.LastAuthor.Id = form.LastAuthor

	if post.Topic == nil {
		post.Topic = &models.Topic{}
	}
	post.Topic.Id = form.Topic
	//get category
	topic := &models.Topic{Id: form.Topic}
	if err := topic.Read("Id"); err == nil {
		if post.Category == nil {
			post.Category = &models.Category{}
		}
		post.Category.Id = topic.Category.Id
	}
	post.ContentCache = utils.RenderMarkdown(post.Content)
}
Esempio n. 2
0
func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	if post.User == nil {
		post.User = &models.User{}
	}
	post.User.Id = form.User

	if post.LastReply == nil {
		post.LastReply = &models.User{}
	}
	post.LastReply.Id = form.LastReply

	if post.LastAuthor == nil {
		post.LastAuthor = &models.User{}
	}
	post.LastAuthor.Id = form.LastAuthor

	if post.Topic == nil {
		post.Topic = &models.Topic{}
	}
	post.Topic.Id = form.Topic

	if post.Category == nil {
		post.Category = &models.Category{}
	}
	post.Category.Id = form.Category

	post.ContentCache = utils.RenderMarkdown(post.Content)
}
Esempio n. 3
0
func (form *PostForm) SavePost(post *models.Post, user *models.User) error {
	utils.SetFormValues(form, post)
	post.Category = &models.Category{Id: form.Category}
	post.Topic = &models.Topic{Id: form.Topic}
	post.User = user
	post.LastReply = user
	post.LastAuthor = user
	post.ContentCache = utils.RenderMarkdown(form.Content)

	// mentioned follow users
	FilterMentions(user, post.ContentCache)

	return post.Insert()
}