Exemple #1
0
 def submit_vote(self):
   user = users.get_current_user()
   if user:
     item1_id = int(self.request.POST['item1'])
     item2_id = int(self.request.POST['item2'])
     comment1 = self.request.POST['comment' + str(item1_id)]
     comment2 = self.request.POST['comment' + str(item2_id)]
     selected_id = int(self.request.POST['optionsRadios'])
     item1 = Item.get_by_id(item1_id)
     item2 = Item.get_by_id(item2_id)
     if selected_id == item1_id:
       item1.wins += 1
       item1.put()
       item2.losses += 1
       item2.put()
     else:
       item2.wins += 1
       item2.put()
       item1.losses += 1
       item1.put()
     if comment1:
       comment = Comment(text=comment1, owner=user, item=item1)
       comment.put()
     if comment2:
       comment = Comment(text=comment2, owner=user, item=item2)
       comment.put()
     self._show_home_page({'success': 'Successfully saved the vote'})
   else:
     self.redirect(users.create_login_url("/"))
	def put(self, projectKey, issueKey, key): #update
		comment = Comment().get(key)
		comment.Issue = Issue().get(issueKey)
		comment.text = getArgument(self.request, 'text', '"text" is a required field!')
		comment.put()
		url = comment.url(self.request.url)
		self.response.headers.add_header("Location", url)
		self.response.out.write(json(url))
	def post(self, projectKey, issueKey): #post = create object
		comment = Comment()
		comment.issue = Issue().get(issueKey)
		comment.text = getArgument(self.request, 'text', '"text" is a required field!')
		comment.put()
		url = comment.url(self.request.url)
		self.response.headers.add_header("Location", url)
		self.response.out.write(json(url))
		self.response.set_status(201)
	def delete(self, projectKey, issueKey, key):
		comment = Comment().get(key)
		comment.delete()
		self.response.out.write(json(str(comment.key())))