def update(self, id, format='html'): """PUT /votes/id: Update an existing item""" try: vote = self._get_vote(id, format) form = dict() try: form = rest_validate(VoteUpdateForm) except formencode.Invalid, i: return fstatus(i.message, format=format, http_code=400) model.meta.Session.begin() vote.weight=form.get("weight") vote.time = datetime.utcnow() model.meta.Session.merge(vote) model.meta.Session.commit() classify.unlearn_vote(vote) classify.learn_vote(vote) log.debug("Updated: %s" % vote) return self.view(vote.id, format=format)
return fstatus(i.message, format=format, http_code=400) user_id = session['user_id'] tweet_id = form.get("tweet_id") if model.findVoteByUserAndTweet(user_id, tweet_id): return fstatus("This rating already exists, please update it instead.", format=format, http_code=409) model.meta.Session.begin() vote = model.Vote(tweet_id, user_id, weight=form.get("weight")) model.meta.Session.add(vote) model.meta.Session.commit() classify.learn_vote(vote) log.debug("Created: %s" % vote) return self.view(vote.id, format=format) @with_auth() @with_format() def update(self, id, format='html'): """PUT /votes/id: Update an existing item""" try: vote = self._get_vote(id, format) form = dict() try: form = rest_validate(VoteUpdateForm) except formencode.Invalid, i: