예제 #1
0
파일: votes.py 프로젝트: pudo/tweetvote
 def delete(self, id, format='html'):
     """DELETE /votes/id: Delete an existing item"""
     try:
         vote = self._get_vote(id, format)
         
         model.meta.Session.begin()
         model.meta.Session.delete(vote)
         model.meta.Session.commit()
         
         classify.unlearn_vote(vote)
         
         return fstatus("Deleted.", format=format)
     except StatusException, se:
         return se.message
예제 #2
0
파일: votes.py 프로젝트: pudo/tweetvote
 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)