Esempio n. 1
0
func (c *GorpController) insertView(q *models.QdbView) error {

	if len(q.Quote) > INPUT_QUOTE_MAX {
		q.Quote = q.Quote[:INPUT_QUOTE_MAX]
	}

	if len(q.Author) > INPUT_AUTHOR_MAX {
		q.Author = q.Author[:INPUT_AUTHOR_MAX]
	}

	e := models.QdbEntry{
		Quote:  q.Quote,
		Author: q.Author,
	}

	err := c.Txn.Insert(&e)

	if err != nil {
		return err
	}

	q.QuoteId = e.QuoteId
	q.Created = e.Created
	q.Rating = e.Rating

	return c.insertTagArray(q.QuoteId, q.Tags)
}
Esempio n. 2
0
// post
func (c *App) Post(quote models.QdbView, page models.Pagination) revel.Result {
	quote.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
	} else {
		err := c.insertView(&quote)

		if err != nil {
			c.Response.Status = http.StatusInternalServerError
			revel.ERROR.Print(err)
			//TODO: redirect to error page
			panic(err)
		}
	}

	c.Session["author"] = quote.Author

	return c.Redirect(routes.App.Index(page))
}