Ejemplo n.º 1
0
	def returnPostById(self, p_id, update = False):
		key = "postidkey"
		postdb = memcache.get(key)
		if not postdb or update:
			postdb = PostsDB.get_by_id(int(p_id))
			memcache.set(key, postdb)
		return postdb
Ejemplo n.º 2
0
	def get_recent_posts(self):
		posts = {}
		postdb = PostsDB.all().order("-rating").fetch(30)
		l = []		
		for post in postdb:
			l.append((post.key().id(), post.title, post.author, post.subject, post.date, post.like_count, 
								post.comment_count, post.tag1, post.tag2, post.tag3, post.like, post.dislike))
		return l
Ejemplo n.º 3
0
	def get_recent_posts(self):
		l = []
		postdb = PostsDB.all().fetch(100)
		for post in postdb:
			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))
		return l
Ejemplo n.º 4
0
	def loadHelloUserDb(self, userdb, update = False):

		key = 'hellouserkey'
		hellouserdb = memcache.get(key)
		if not hellouserdb or update:
			hellouserdb = PostsDB.all().filter('userdb =',userdb).fetch(30)
			memcache.set(key, hellouserdb)
			hellouserdb = list(hellouserdb)
		return hellouserdb
Ejemplo n.º 5
0
	def loadTrendingPostsDb(self, filter = "", order = "",  update = False):

		key = 'trendingkey'
		postsdb = memcache.get(key)
		if not postsdb or update:
			postsdb = PostsDB.all().order(order).fetch(30)
			memcache.set(key,postsdb)
			postsdb = list(postsdb)
		return postsdb
Ejemplo n.º 6
0
	def loadRecentPostsDb(self, filter = "", order = "", update = False):
		
		# print 'hi'  Seems working but the statement 'db fetch' was never printed. But 'hi' got printed.
		key = 'recentkey'
		postsdb = memcache.get(key)
		if not postsdb or update:
			postsdb = PostsDB.all().order('-date').fetch(30)
			memcache.set(key,postsdb)
			postsdb = list(postsdb)
		return postsdb
Ejemplo n.º 7
0
	def get_tagged_posts(self,tagname):
		l = []
		postdb = PostsDB.all().filter('tag1 =',tagname).fetch(100)		
		for post in postdb:
			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,post.post))
	
		postdb = PostsDB.all().filter('tag2 =',tagname).fetch(100)		
		for post in postdb:
			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,post.post))
	
		postdb = PostsDB.all().filter('tag3 =',tagname).fetch(100)		
		for post in postdb:
			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,post.post))
		return set(l)
Ejemplo n.º 8
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.º 9
0
	def load_upload(self,title, content, username, username_ck, tag1 = "", tag2 = "", tag3 = ""):
		users = UserDB.all().filter('username ='******'-rating', update = True)
			self.loadAllTagsDb(update = True)

			self.redirect('/done/%d'%post_username.key().id())
			break
		# if not users:
		# 	content = "no usres returned from the query " +  username_ck
		"""instead of passing to the new_page redirect to the done page"""
Ejemplo n.º 10
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)