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

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

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

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

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

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

	post.ContentCache = RenderPostContent(post.Content)
}
Esempio n. 2
0
func (form *PostForm) UpdatePost(post *Post, user *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 = RenderPostContent(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...)
}
Esempio n. 3
0
func (form *UserAdminForm) SetToUser(user *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)
}
Esempio n. 4
0
func (form *CommentAdminForm) SetFromComment(comment *Comment) {
	utils.SetFormValues(comment, form)

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

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

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

	if article.LastAuthor != nil {
		form.LastAuthor = article.LastAuthor.Id
	}
}
Esempio n. 6
0
func (form *PostForm) SavePost(post *Post, user *User) error {
	utils.SetFormValues(form, post)
	post.Category = &Category{Id: form.Category}
	post.Topic = &Topic{Id: form.Topic}
	post.User = user
	post.LastReply = user
	post.LastAuthor = user
	post.ContentCache = RenderPostContent(form.Content)

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

	return post.Insert()
}
Esempio n. 7
0
func (form *CommentAdminForm) SetToComment(comment *Comment) {
	utils.SetFormValues(form, comment)

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

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

	comment.MessageCache = RenderPostContent(comment.Message)
}
Esempio n. 8
0
func (form *ArticleAdminForm) SetToArticle(article *Article) {
	utils.SetFormValues(form, article)

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

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

	article.ContentCache = RenderPostContent(article.Content)
	article.ContentCacheZhCn = RenderPostContent(article.ContentZhCn)
}
Esempio n. 9
0
func (form *ProfileForm) SaveUserProfile(user *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
}
Esempio n. 10
0
func (form *PostAdminForm) SetFromPost(post *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
	}

	if post.Category != nil {
		form.Category = post.Category.Id
	}
}
Esempio n. 11
0
func (form *TopicAdminForm) SetToTopic(topic *Topic) {
	utils.SetFormValues(form, topic, "Id")
}
Esempio n. 12
0
func (form *TopicAdminForm) SetFromTopic(topic *Topic) {
	utils.SetFormValues(topic, form)
}
Esempio n. 13
0
func (form *PostForm) SetFromPost(post *Post) {
	utils.SetFormValues(post, form)
	form.Category = post.Category.Id
	form.Topic = post.Topic.Id
}
Esempio n. 14
0
func (form *UserAdminForm) SetFromUser(user *User) {
	utils.SetFormValues(user, form)
}
Esempio n. 15
0
func (form *CategoryAdminForm) SetFromCategory(cat *Category) {
	utils.SetFormValues(cat, form)
}
Esempio n. 16
0
func (form *CategoryAdminForm) SetToCategory(cat *Category) {
	utils.SetFormValues(form, cat, "Id")
}
Esempio n. 17
0
func (form *ProfileForm) SetFromUser(user *User) {
	utils.SetFormValues(user, form)
}