Exemplo n.º 1
0
func (form *PostForm) UpdatePost(post *models.Post, user *models.User) error {
	changes := utils.FormChanges(post, form)
	if len(changes) == 0 {
		return nil
	}
	utils.SetFormValues(form, post)
	post.Category.Id = form.Category
	post.Topic.Id = form.Topic
	for _, c := range changes {
		if c == "Content" {
			post.ContentCache = utils.RenderMarkdown(form.Content)
			changes = append(changes, "ContentCache")
		}
	}

	// update last edit author
	if post.LastAuthor != nil && post.LastAuthor.Id != user.Id {
		post.LastAuthor = user
		changes = append(changes, "LastAuthor")
	}

	changes = append(changes, "Updated")

	return post.Update(changes...)
}
Exemplo 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
	//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)
}
Exemplo n.º 3
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)
}
Exemplo n.º 4
0
func (form *UserAdminForm) SetToUser(user *models.User) {
	// set md5 value if the value is an email
	if strings.IndexRune(form.GrEmail, '@') != -1 {
		form.GrEmail = utils.EncodeMd5(form.GrEmail)
	}

	utils.SetFormValues(form, user)
}
Exemplo n.º 5
0
func (form *TopicAdminForm) SetToTopic(topic *models.Topic) {
	utils.SetFormValues(form, topic, "Id")
	if topic.Category != nil {
		topic.Category.Id = form.Category
	} else {
		topic.Category = &models.Category{Id: form.Category}
	}
}
Exemplo n.º 6
0
func (form *CommentAdminForm) SetFromComment(comment *models.Comment) {
	utils.SetFormValues(comment, form)

	if comment.User != nil {
		form.User = comment.User.Id
	}

	if comment.Post != nil {
		form.Post = comment.Post.Id
	}
}
Exemplo n.º 7
0
func (form *ArticleAdminForm) SetFromArticle(article *models.Article) {
	utils.SetFormValues(article, form)

	if article.User != nil {
		form.User = article.User.Id
	}

	if article.LastAuthor != nil {
		form.LastAuthor = article.LastAuthor.Id
	}
}
Exemplo n.º 8
0
func (form *PageAdminForm) SetFromPage(page *models.Page) {
	utils.SetFormValues(page, form)

	if page.User != nil {
		form.User = page.User.Id
	}

	if page.LastAuthor != nil {
		form.LastAuthor = page.LastAuthor.Id
	}
}
Exemplo n.º 9
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()
}
Exemplo n.º 10
0
func (form *PageAdminForm) SetToPage(page *models.Page) {
	utils.SetFormValues(form, page)

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

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

	page.ContentCache = utils.RenderMarkdown(page.Content)
}
Exemplo n.º 11
0
func (form *CommentAdminForm) SetToComment(comment *models.Comment) {
	utils.SetFormValues(form, comment)

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

	if comment.Post == nil {
		comment.Post = &models.Post{}
	}
	comment.Post.Id = form.Post

	comment.MessageCache = utils.RenderMarkdown(comment.Message)
}
Exemplo n.º 12
0
func (form *ArticleAdminForm) SetToArticle(article *models.Article) {
	utils.SetFormValues(form, article)

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

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

	article.ContentCache = utils.RenderMarkdown(article.Content)
	article.ContentCacheZhCn = utils.RenderMarkdown(article.ContentZhCn)
}
Exemplo n.º 13
0
func (this *CategoryRouter) NewSubmit() {
	form := post.CategoryForm{Locale: this.Locale}
	this.TplNames = "category/new.html"
	if !this.ValidFormSets(&form) {
		return
	}

	var category models.Category

	utils.SetFormValues(&form, &category)

	if err := category.Insert(); err == nil {
		this.Redirect(category.Link(), 302)
	}

}
Exemplo n.º 14
0
func (form *PostAdminForm) SetFromPost(post *models.Post) {
	utils.SetFormValues(post, form)

	if post.User != nil {
		form.User = post.User.Id
	}

	if post.LastReply != nil {
		form.LastReply = post.LastReply.Id
	}

	if post.LastAuthor != nil {
		form.LastAuthor = post.LastAuthor.Id
	}

	if post.Topic != nil {
		form.Topic = post.Topic.Id
	}
}
Exemplo n.º 15
0
func (form *ProfileForm) SaveUserProfile(user *models.User) error {
	// set md5 value if the value is an email
	if strings.IndexRune(form.GrEmail, '@') != -1 {
		form.GrEmail = utils.EncodeMd5(form.GrEmail)
	}

	changes := utils.FormChanges(user, form)
	if len(changes) > 0 {
		// if email changed then need re-active
		if user.Email != form.Email {
			user.IsActive = false
			changes = append(changes, "IsActive")
		}

		utils.SetFormValues(form, user)
		return user.Update(changes...)
	}
	return nil
}
Exemplo n.º 16
0
func (form *TopicAdminForm) SetToTopic(topic *models.Topic) {
	utils.SetFormValues(form, topic, "Id")
}
Exemplo n.º 17
0
func (form *TopicAdminForm) SetFromTopic(topic *models.Topic) {
	utils.SetFormValues(topic, form)
	form.Category = topic.Category.Id
}
Exemplo n.º 18
0
func (form *CategoryAdminForm) SetToCategory(cat *models.Category) {
	utils.SetFormValues(form, cat, "Id")
}
Exemplo n.º 19
0
func (form *CategoryAdminForm) SetFromCategory(cat *models.Category) {
	utils.SetFormValues(cat, form)
}
Exemplo n.º 20
0
func (form *BulletinAdminForm) SetToBulletin(bulletin *models.Bulletin) {
	utils.SetFormValues(form, bulletin, "Id")
}
Exemplo n.º 21
0
func (form *UserAdminForm) SetFromUser(user *models.User) {
	utils.SetFormValues(user, form)
}
Exemplo n.º 22
0
func (form *ProfileForm) SetFromUser(user *models.User) {
	utils.SetFormValues(user, form)
}
Exemplo n.º 23
0
func (form *BulletinAdminForm) SetFromBulletin(bulletin *models.Bulletin) {
	utils.SetFormValues(bulletin, form)
}
Exemplo n.º 24
0
func (form *TopicAdminForm) SetFromTopic(topic *models.Topic) {
	utils.SetFormValues(topic, form)
}
Exemplo n.º 25
0
func (form *PostForm) SetFromPost(post *models.Post) {
	utils.SetFormValues(post, form)
	form.Category = post.Category.Id
	form.Topic = post.Topic.Id
}