Created
September 1, 2010 20:18
-
-
Save emilepetrone/561278 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class VoteHandler(webapp.RequestHandler): | |
| def get(self): | |
| #See if logged in | |
| self.Session = Session() | |
| if not 'userkey' in self.Session: | |
| doRender( | |
| self, | |
| 'base/index.html', | |
| {'error' : 'Please login to vote'}) | |
| return | |
| #If user hasn't voted - if user doesn't have a vote on that image object | |
| key = self.request.get('photo_id') | |
| vurl = models.Image.get_by_id(int(key)) | |
| #pull current site vote total & add 1 | |
| existing_vote = models.Vote.all().filter('user=', self.Session['userkey']).filter('photo=', vurl) | |
| if existing_vote != 0: | |
| self.redirect('/', { }) | |
| else: | |
| newvote = models.Vote(user=self.Session['userkey'], url=vurl) | |
| vurl.votes += 1 | |
| vurl.put() | |
| logging.info('Adding a vote') | |
| #Create a new Vote object | |
| newvote = models.Vote(user=self.Session['userkey'], url=vurl) | |
| newvote.put() | |
| self.redirect('/', { }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment