Ejemplo n.º 1
0
	def post(self,username):
		is_follow = self.request.POST.get('follow')
		is_get_image = self.request.POST.get('upload_image')
		if is_get_image:
			avatar = images.resize(self.request.get('image'),90,90)
			whos_page = username
			username_ck = str(self.request.cookies.get('username_ck'))
			userdb = UserDB.all().filter('username ='******'username_ck'))
			userdb = UserDB.all().filter('username ='******'/hello_user/%s'%username)
Ejemplo n.º 2
0
	def get(self,username):
		"""The homepage of username is hidden from non-logged in user. This may prompt him to register for the site."""

		username_ck = str(self.request.cookies.get('username_ck'))
		if not username_ck or username_ck == 'None':
			self.redirect('/login')
		else:
			username_sec = self.encrypt_username(username)		
			userdb = UserDB.all().filter('username ='******'userdb =',i).fetch(100)

				for post in posts:
					date = self.get_date_without_decimal_in_seconds(post.date)
					l.append((post.key().id(), post.title, post.author, post.subject, date, post.like_count, 
								post.comment_count, post.tag1, post.tag2, post.tag3, post.like, post.dislike))
			user_posts = l
			whos_page = username 
			username = self.return_username_if_valid_cookie(username_ck)

			q = PeopleDB.all().filter('people_follows =',username_ck).fetch(100)
			following = []
			for i in q:
				following.append(i.people_followed)			

			if whos_page != username:
				if whos_page in following:
					follow = ""
				else:
					follow = "follow"
				following = ""
			else:
				follow = ""

			self.pass_template_value_hellouser_page(logout = 'Logout',image_id_key = image_key, username = username ,whos_page = whos_page,
										 follow = follow, posts = user_posts, following = following)
Ejemplo n.º 3
0
	def post(self,post_id):
		
		self.response.out.write('in post')
		username_ck = str(self.request.cookies.get('username_ck'))
		username = self.return_username_if_valid_cookie(username_ck)
		if not username or username == "None":
			pass
		else:
			is_comment = self.request.POST.get('submit_comment')
			is_like = self.request.POST.get('like')
			is_dislike = self.request.POST.get('dislike')
			if is_comment:
				if not username or username == "None":
					self.response.out.write("login")
				comment = self.request.get('comment')
				if not comment or comment.isspace():
					self.redirect('/done/%d'%int(post_id))
				else:
					postsdb = PostsDB.get_by_id(int(post_id))
					commentsdb = CommentsDB(postsdb = postsdb,comment = comment, commenter = username)
					postsdb.comment_count = postsdb.comment_count + 1
					postsdb.rating = postsdb.rating + 0.6
					postsdb.put()
					commentsdb.put()

					"""caching"""
					self.returnPostById(post_id, True)
					self.loadComments(postsdb, True)
					self.loadRecentPostsDb(order = '-date', update = True)
					self.loadTrendingPostsDb(order = '-rating', update = True)


					self.redirect('/done/%d'%int(post_id))
			elif is_like:
				peopledb = PeopleDB.all().filter('posts_id =',int(post_id)).filter('username_liked =',username)
				if peopledb.count() == 0:
					self.response.out.write('not found')#display it int a box
					peopledb = PeopleDB(posts_id = int(post_id),has_liked_boolean = True, username_liked = username)
					peopledb.put()
					postsdb = PostsDB.get_by_id(int(post_id))
					postsdb.like_count = postsdb.like_count + 1
					postsdb.like = postsdb.like + 1
					postsdb.rating = postsdb.rating + 0.4
					postsdb.put()
					self.response.out.write('you have successfully liked this post for the first time')#display it int a box
				else:
					peopledb.fetch(1)
					for i in peopledb:
						if i.has_liked_boolean:
							self.response.out.write('you cannot like more than once')#display it int a box
						else:
							i.has_liked_boolean = True
							i.put()
							postsdb = PostsDB.get_by_id(int(post_id))
							postsdb.like_count = postsdb.like_count + 1
							postsdb.like = postsdb.like + 1
							postsdb.rating = postsdb.rating + 0.4
							postsdb.put()							
							self.response.out.write('you have successfully liked this post after disliking it')#display it in a box in js
							break

				"""caching"""
				self.returnPostById(post_id, True)	
				self.loadRecentPostsDb(order = '-date', update = True)
				self.loadTrendingPostsDb(order = '-rating', update = True)


				self.redirect('/done/%d'%int(post_id))
			elif is_dislike:
				peopledb = PeopleDB.all().filter('posts_id =',int(post_id)).filter('username_liked =',username)
				if peopledb.count() == 0:
					self.response.out.write('not found')
					peopledb = PeopleDB(posts_id = int(post_id), has_liked_boolean = False, username_liked = username)
					peopledb.put()
					postsdb = PostsDB.get_by_id(int(post_id))
					postsdb.like_count = postsdb.like_count - 1
					postsdb.dislike = postsdb.dislike - 1 
					postsdb.rating = postsdb.rating + 0.2
					postsdb.put()
					self.response.out.write('you have successfully disliked the post for the first time')#display it int a box
				else:
					peopledb.fetch(1)
					for i in peopledb:
						if not i.has_liked_boolean:
							self.response.out.write('you cannot dislike more than once')#display it int a box
						else:
							i.has_liked_boolean = False
							i.put()
							postsdb = PostsDB.get_by_id(int(post_id))
							postsdb.like_count = postsdb.like_count - 1
							postsdb.dislike = postsdb.dislike - 1 
							postsdb.rating = postsdb.rating + 0.2
							postsdb.put()	
							self.response.out.write('you have successfully disliked this post after liking it')#display it int a box
							break

				"""caching"""
				self.returnPostById(post_id, True)	
				self.loadRecentPostsDb(order = '-date', update = True)
				self.loadTrendingPostsDb(order = '-rating', update = True)


				self.redirect('/done/%d'%int(post_id))	




		if not username_ck or username_ck == 'None':
			login = "******"
			signup = "Signup"
			username = ""
			logout = ""
		else:
			username = self.return_username_if_valid_cookie(username_ck)
			login = ""
			signup = ""
			logout = "Logout"

		is_tag_search = self.request.POST.get('tag_search')		
		if is_tag_search:
			search_key = str(self.request.get('search_key'))
			is_tag_or_people = self.request.POST.get('tags_or_people')
			# is_tag_or_people = is_tag_or_people.strip()
			search_key = search_key.strip()
			if not search_key or not is_tag_or_people:
				self.redirect('/trending')
			else:
				tags = SearchPage().get_search_result(search_key,0,is_tag_or_people)
				tags = sorted(tags, key = lambda x: x[1] )
				l = []
				for (tag,rank) in tags:
					l.append(tag)	
				display_tag = False
				display_people = False
				if is_tag_or_people == 'tags':
					display_tag = True
				if is_tag_or_people == "people":
					display_people = True
				self.pass_template_value_search_page(logout = logout, username = username,
									signup = signup, login = login, search_key = search_key, tags = l,
									display_tag = display_tag, display_people = display_people)