Example #1
0
func (c Blog) Update(article *models.Article) revel.Result {
	if c.ActiveUser != nil {
		check := models.GetArticleByObjectId(c.MongoSession, article.Id)
		if check.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			article.Tags = strings.Split(c.Params.Values["article.Tags"][0], ",")
			article.Validate(c.Validation)
			if c.Validation.HasErrors() {
				c.Validation.Keep()
				c.FlashParams()
				c.Flash.Error("Please correct the errors below.")
				return c.Redirect("/blog/%s/edit", article.Id.Hex())
			}

			// @todo properly implement this
			article.Author_id = check.Author_id
			article.Published = check.Published
			article.Posted = check.Posted

			article.Save(c.MongoSession)
			return c.Redirect("/blog/%s", article.Id.Hex())
		}
		return c.Forbidden("You do not have permission to edit this resource.")
	}
	return c.Redirect(User.GetLogin)
}
Example #2
0
func (c Blog) PostCreate(article *models.Article) revel.Result {
	if c.ActiveUser != nil {
		article.Tags = strings.Split(c.Params.Values["article.Tags"][0], ",")
		article.Validate(c.Validation)
		if c.Validation.HasErrors() {
			c.Validation.Keep()
			c.FlashParams()
			c.Flash.Error("Please correct the errors below.")
			return c.Redirect(Blog.GetCreate)
		}

		// Set calculated fields
		article.Author_id = c.ActiveUser.Id
		article.Published = true
		article.Posted = time.Now()
		article.Id = bson.NewObjectId()
		article.Save(c.MongoSession)
	}
	return c.Redirect(Application.Index)
}