Exemplo n.º 1
0
	def post(self, id):
		idea = Idea.get_by_id(int(id))	
		
		if(idea):
			author_key = Idea.author.get_value_for_datastore(idea)
			
			if(author_key == self.current_user.key() or self.admin):
				validated, title, answers = Idea.validate(self.request, idea)
		
				if not validated:
					self.redirect("/idea/"+str(idea.key().id())+"/edit")
				else:
					idea.title = title
					idea.answers = answers
					idea.put()
			
					values = {
						"response": "Idea updated",
						"next": {
							"content": "Back",
							"url": "/idea/"+str(idea.key().id()),
						}
					}
					path = "feedback.html"		
					self.render(path, values)
					
			else:
				raise GetpitchdError("Not authorized to edit idea")

		else:
			raise GetpitchdError("Idea does not exist")
Exemplo n.º 2
0
	def post(self, id):
		idea = Idea.get_by_id(int(id))
		
		if(idea):
			author_key = Idea.author.get_value_for_datastore(idea)

			if(author_key == self.current_user.key() or self.admin):
				idea.delete()
				
				user = self.current_user
				user.ideas -= 1
				user.put()
		
				values = {
					"response": "Your idea has been deleted.",
					"next": {
						"content": "Back to homepage",
						"url":"/",
					}
				}
				path = "feedback.html"		
				self.render(path, values)
			else:
				raise GetpitchdError("Not authorized to delete idea")
		else:
			raise GetpitchdError("Idea does not exist")
Exemplo n.º 3
0
	def get(self, id):
		idea = Idea.get_by_id(int(id))
		
		if(idea):
			author_key = Idea.author.get_value_for_datastore(idea)
			
			if(author_key == self.current_user.key() or self.admin):
				extended_idea = Idea.get_extended_idea(idea)
								
				values = {
					"status": "edit",
					"title": extended_idea["title"],
					"id": extended_idea["id"],
					"url": "/idea/" + str(extended_idea["id"]) + "/edit",
					"steps": extended_idea["extended_steps"],
				}
				path = "idea/pitch.html"
				self.render(path, values)		
			
			else:
				raise GetpitchdError("Not authorized to edit idea")
		
		else:
			raise GetpitchdError("Idea does not exist")
Exemplo n.º 4
0
	def post(self, id):
		idea = Idea.get_by_id(int(id))
		
		if(idea):
			content = self.request.get("feedback")
			
			if(content=="positive" or content=="negative"):
				key_name = str(self.current_user.key().id()) + "_" + str(idea.key().id())
				existing_feedback = Feedback.get_by_key_name(key_name)
				
				if not existing_feedback:	
					feedback = Feedback(
						key_name = key_name,
						author = self.current_user.key(),
						idea = idea.key(),
						content = content,
					)
					feedback.put()
								
					if(content == "positive"):
						idea.positive += 1
					else:
						idea.negative += 1
				
					text = self.request.get("text")
					if text:
						comment = Comment(
							idea = idea.key(),
							author = self.current_user.key(),
							text = text,
						)
						comment.put()
						idea.comments += 1
				
					idea.put()
					
					if text:
						event = IdeaFeedbackEvent(self.current_user, feedback, idea, text)
					else:
						event = IdeaFeedbackEvent(self.current_user, feedback, idea)
					
					if(content == "positive"):
						author_key = Idea.author.get_value_for_datastore(idea)
						author = User.get(author_key)
						
						text = "I'm enthusiastic about a new startup idea pitched by @" + author.username + " on @gopitchme: " + idea.title
						url = config.SITE_URL + "/idea/" + str(idea.key().id())
						tweet = generate_tweet(text, url)
						
						response = "Feedback sent"
						call_to_action = "Why not tweeting this idea to your friends?"
						values = {
							"response": response,
							"call_to_action": call_to_action,
							"tweet": tweet,
							"skip_url": "/idea/" + str(idea.key().id()),
						}
						path = "idea/tweet.html"
					else:
						values = {
							"response": "Thanks for your feedback",
							"next": {
								"content": "Back",
								"url": "/idea/"+str(idea.key().id()),
							}
						}	
						path = "feedback.html"
					
					self.render(path, values)
				else:
					raise GetpitchdError("Feedback already sent")
			else:
				raise GetpitchdError("Forbidden feedback")
		else:
			raise GetpitchdError("Idea does not exist")
Exemplo n.º 5
0
	def get(self, id):
		idea = Idea.get_by_id(int(id))
		
		if(idea):
			extended_idea = Idea.get_extended_idea(idea)
		
			author = User.get(Idea.author.get_value_for_datastore(idea))
			
			feedback = None
			if(self.current_user):
				feedback = Feedback.all().filter("author =", self.current_user.key()).filter("idea =", idea.key()).get()
			
			# Fetch comments
			comments = Comment.all().filter('idea = ', idea.key()).fetch(1000)
			
			# Filter comments which are not replies to and those from the others
			threaded, children, depths = [], [], []
			for comment in comments:
				if Comment.reply_to.get_value_for_datastore(comment) is None:
					threaded.append(comment)
					depths.append(0)
				else:
					children.append(comment)
			
			# Filter comments which are not replies to by date (desc)
			tosort = [(c.created, c) for c in threaded]
			tosort.sort()
			tosort.reverse()
			threaded = [c for _, c in tosort]
						
			# Filter children by date (asc)
			tosort = [(c.created, c) for c in children]
			tosort.sort()
			children = [c for _, c in tosort]
						
			# Insert children comments at the right place
			for comment in children:
				i = 0
				parents = list(threaded)
				for parent in parents:
					if parent.key() == Comment.reply_to.get_value_for_datastore(comment):
						threaded.insert(1 + i, comment)
						depths.insert(1 + i, depths[i] + 1)
						i = i + 2
					else:
						i = i + 1
			
			# Get authors 
			authors_keys = [Comment.author.get_value_for_datastore(c) for c in threaded]
			authors = User.get(authors_keys)
			
			values = {
				"extended_idea": extended_idea,
				"author": author,
				"feedback": feedback,
				"comments": zip(authors, threaded, depths),
			}
			path = "idea/idea.html"
			self.render(path, values)
		else:
			raise GetpitchdError("Idea does not exist")