Beispiel #1
0
func (form *CommentAdminForm) SetToComment(comment *models.Comment) {
	utils.SetFormValues(form, comment)

	comment.UserId = int64(form.User)
	comment.PostId = int64(form.Post)
	comment.MessageCache = utils.RenderMarkdown(comment.Message)
}
Beispiel #2
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.CategoryId = form.Category
	post.TopicId = 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.LastAuthorId != user.Id {
		post.LastAuthorId = user.Id
		changes = append(changes, "LastAuthor")
	}

	changes = append(changes, "Updated")

	return models.UpdateById(post.Id, post, models.Obj2Table(changes)...)
}
Beispiel #3
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)
}
Beispiel #4
0
func (form *PostAdminForm) SetFromPost(post *models.Post) {
	utils.SetFormValues(post, form)

	form.User = post.UserId
	form.LastReply = post.LastReplyId
	form.LastAuthor = post.LastAuthorId
	form.Topic = post.TopicId
}
Beispiel #5
0
func (form *PageAdminForm) SetToPage(page *models.Page) {
	utils.SetFormValues(form, page)

	page.UserId = int64(form.User)
	page.LastAuthorId = int64(form.LastAuthor)

	page.ContentCache = utils.RenderMarkdown(page.Content)
}
Beispiel #6
0
func (form *PostAdminForm) SetToPost(post *models.Post) {
	utils.SetFormValues(form, post)

	post.UserId = form.User
	post.LastReplyId = form.LastReply
	post.LastAuthorId = form.LastAuthor
	post.TopicId = form.Topic
	//get category
	if topic, err := models.GetTopicById(form.Topic); err == nil {
		post.CategoryId = topic.CategoryId
	}
	post.ContentCache = utils.RenderMarkdown(post.Content)
}
Beispiel #7
0
func (form *PostForm) SavePost(post *models.Post, user *models.User) error {
	utils.SetFormValues(form, post)
	post.CategoryId = form.Category
	post.TopicId = form.Topic
	post.UserId = user.Id
	post.LastReplyId = user.Id
	post.LastAuthorId = user.Id
	post.CanEdit = true
	post.ContentCache = utils.RenderMarkdown(form.Content)

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

	return post.Insert()
}
Beispiel #8
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 models.UpdateById(user.Id, user, changes...)
	}
	return nil
}
Beispiel #9
0
func (form *PostForm) SetFromPost(post *models.Post) {
	utils.SetFormValues(post, form)
	form.Category = post.CategoryId
	form.Topic = post.TopicId
}
Beispiel #10
0
func (form *PageAdminForm) SetFromPage(page *models.Page) {
	utils.SetFormValues(page, form)

	form.User = int(page.UserId)
	form.LastAuthor = int(page.LastAuthorId)
}
Beispiel #11
0
func (form *BulletinAdminForm) SetToBulletin(bulletin *models.Bulletin) {
	utils.SetFormValues(form, bulletin, "Id")
}
Beispiel #12
0
func (form *BulletinAdminForm) SetFromBulletin(bulletin *models.Bulletin) {
	utils.SetFormValues(bulletin, form)
}
Beispiel #13
0
func (form *CategoryAdminForm) SetFromCategory(cat *models.Category) {
	utils.SetFormValues(cat, form)
}
Beispiel #14
0
func (form *CommentAdminForm) SetFromComment(comment *models.Comment) {
	utils.SetFormValues(comment, form)

	form.User = int(comment.UserId)
	form.Post = int(comment.PostId)
}
Beispiel #15
0
func (form *CategoryAdminForm) SetToCategory(cat *models.Category) {
	utils.SetFormValues(form, cat, "Id")
}
Beispiel #16
0
func (form *TopicAdminForm) SetFromTopic(topic *models.Topic) {
	utils.SetFormValues(topic, form)
	form.Category = int(topic.CategoryId)
}
Beispiel #17
0
func (form *UserAdminForm) SetFromUser(user *models.User) {
	utils.SetFormValues(user, form)
}
Beispiel #18
0
func (form *TopicAdminForm) SetToTopic(topic *models.Topic) {
	utils.SetFormValues(form, topic, "Id")
	topic.CategoryId = int64(form.Category)
}
Beispiel #19
0
func (form *ProfileForm) SetFromUser(user *models.User) {
	utils.SetFormValues(user, form)
}