def get(self, their_usercode):
		self.init_session()
		if self.do_redirect(): return

		my_usercode = self.get_key('usercode')
		
		if my_usercode is None or their_usercode is None or len(their_usercode) == 0:
			self.restore_previous('Oops! Something went wrong there...')
			return
			
		their_userdata = UserData.get_by_code(their_usercode)
		
		if FriendRequest.already_present(my_usercode, their_usercode):
			self.restore_previous('Your friend request is still awaiting the approval of %s.' % their_userdata.nickname)
			return
		elif FriendRequest.already_present(their_usercode, my_usercode):
			self.redirect(ApproveFriend)
			return
			
		if Friend.already_present(my_usercode, their_usercode):
			self.restore_previous('You and %s are already friends.' % their_userdata.nickname)
			return
			
		FriendRequest.make_request(my_usercode, their_usercode)
		
		self.restore_previous('Friend request sent to %s' % their_userdata.nickname)
	def get(self, their_usercode):
		self.init_session()
		if self.do_redirect(): return
		
		my_usercode = self.get_key('usercode')
		
		if my_usercode is None or their_usercode is None or len(their_usercode) == 0:
			self.restore_previous('Oops! Something went wrong there...')
			return
		
		their_userdata = UserData.get_by_code(their_usercode)

		if Friend.already_present(my_usercode, their_usercode):
			self.restore_previous('You and %s are already friends.' % their_userdata.nickname)
			return

		if not FriendRequest.already_present(their_usercode, my_usercode):
			self.restore_previous('%s has not requested to add you as a friend.' % their_userdata.nickname)
			return

		FriendRequest.unmake_request(my_usercode, their_usercode)
		FriendRequest.unmake_request(their_usercode, my_usercode)
		Friend.make_friends(my_usercode, their_usercode)
		Friend.make_friends(their_usercode, my_usercode)

		self.restore_previous('You are now friends with %s' % their_userdata.nickname)
예제 #3
0
	def load_userdata_into_session(session):
		if 'user' in session:
			user = session['user']
		#	 is user in the userdata table? else make it and go to the settings page
			userdata = UserData.get_by_user(user)
			if userdata is None:
				userdata = UserData()
				userdata.usercode = Usercode().new_code()
				userdata.user = user
				userdata.email = user.email()
				userdata.nickname = user.nickname()
				userdata.apikey = Apikey().new_code()
				userdata.pastes_hidden_by_default = False
				userdata.put()
				session['redirect'] = '/settings'
				session['flash'] = 'Maybe you\'d like to change your default settings. If not, <a href="/">paste away</a>.'
			session['usercode'] = userdata.usercode
			session['nickname'] = userdata.nickname
			session['email'] = userdata.email
			session['pastes_hidden_by_default'] = userdata.pastes_hidden_by_default
			session['friends_hidden_by_default'] = userdata.friends_hidden_by_default
			session['num_friend_requests'] = FriendRequest.get_number_of_requests(userdata.usercode)
			session['got_userdata'] = True
		else:
			session['nickname'] = 'Anonymous'
			session['pastes_hidden_by_default'] = False
			session['friends_hidden_by_default'] = False
			session['num_friend_requests'] = 0
			session['got_userdata'] = False
		return session
	def get(self, usercode=None):
		self.init_session()
		if self.do_redirect(): return
			
		if usercode is None:
			usercode = self.get_key('usercode')
			if usercode is None: # no session
				self.redirect('/login')
				return
		elif usercode[0] == '/':
			usercode = usercode[1:]
			
		your_friends = (usercode == self.get_key('usercode'))
			
		userdata = UserData.get_by_code(usercode)
		if your_friends:
			friend_requests = FriendRequest.get_who_requested_to_follow_user(usercode)
			request_codes = [request.my_code for request in friend_requests]
			num_requests = len(request_codes)
			if num_requests == 0:
				request_data = []
			else:
				request_data = UserData.get_by_codes(request_codes)
			self.template_values.update({
				'num_requests': num_requests,
				'request_data': request_data
			})
		
		if not your_friends and userdata.friends_hidden_by_default:
			deny_listing = True
		else:
			deny_listing = False
			friends = Friend.get_who_i_follow(usercode)
			friend_codes = [friend.their_code for friend in friends]
			num_friends = len(friend_codes)
			if num_friends == 0:
				friend_data = []
			else:
				friend_data = UserData.get_by_codes(friend_codes)
			self.template_values.update({
				'num_friends': num_friends,
				'friend_data' : friend_data,
			})
			
		self.template_values.update({
			'nickname': userdata.nickname,
			'your_friends': your_friends,
			'deny_listing' : deny_listing
		})
		
		path = get_template_path('list_friends.html')
		self.response.out.write(template.render(path, self.template_values, debug=True))
예제 #5
0
	def get_session(request_uri):
		session = sessions.Session()
		user = users.get_current_user()
		session['login_url'] = users.create_login_url(request_uri)
		session['logout_url'] = users.create_logout_url(request_uri)
		if 'user' in session and session['user'] != user:
			session.delete()
			session = sessions.Session()
		if user is None:
			return PersistentRequestHandler.load_userdata_into_session(session)
		else:
			session['user'] = user
			if 'got_userdata' in session and session['got_userdata']:
				session['num_friend_requests'] = FriendRequest.get_number_of_requests(session['usercode'])
				return session
			return PersistentRequestHandler.load_userdata_into_session(session)
예제 #6
0
	def get(self, usercode=None):
		self.init_session()
		if self.do_redirect(): return
		
		if usercode is None:
			usercode = self.get_key('usercode')
			if usercode is None:
				self.redirect('/login')
				return
			else:
				self.redirect('/profile/'+usercode)
				return
		elif usercode[0] == '/':
			usercode = usercode[1:]
		
		my_usercode = self.get_key('usercode')
		your_profile = (usercode == self.get_key('usercode'))

		if not your_profile:
			userdata = UserData.get_by_code(usercode)
			if not (my_usercode is None):
				are_friends = Friend.already_present(my_usercode, usercode)
				if not are_friends:
					
					if not userdata.friends_hidden_by_default:
						list_link = '/friends/'+usercode
					else:
						list_link = None
					
					if FriendRequest.already_present(my_usercode, usercode):
						#print "AWAITING REPLY"
						awaiting_reply = True
						approve_link = reject_link = None
						friend_link = unfriend_link = None
					elif FriendRequest.already_present(usercode, my_usercode):
						#print "APPROVE REJECT"
						awaiting_reply = False
						approve_link = '/friends/approve/'+usercode
						reject_link = '/friends/reject/'+usercode
						friend_link = unfriend_link = None
					else:
						friend_link = '/friends/request/'+usercode
						unfriend_link = None
						approve_link = reject_link = awaiting_reply = None
				else:
					friend_link = None
					unfriend_link = '/friends/remove/'+usercode
					list_link = '/friends/'+usercode
					approve_link = reject_link = awaiting_reply = None
			else:
				are_friends = False
				approve_link = reject_link = awaiting_reply = None
				friend_link = unfriend_link = list_link = None
			pastes = Paste.get_public_by_usercode(usercode)
			self.template_values.update({ 
				'prof_nickname': userdata.nickname,
				'prof_usercode': usercode,
				'profile_link': '/profile/'+usercode,
				'pastes': pastes,
				'num_pastes': pastes.count(),
				'are_friends': are_friends,
				'your_profile': your_profile,
				'friend_link': friend_link,
				'unfriend_link': unfriend_link,
				'list_link': list_link,
				'approve_link': approve_link,
				'reject_link': reject_link,
				'awaiting_reply': awaiting_reply
			})
		else:
			pastes = Paste.get_all_by_usercode(usercode)	
			self.template_values.update({	
				'prof_nickname': self.session['nickname'],
				'prof_usercode': usercode, 
				'profile_link': '/profile/'+usercode,
				'pastes': pastes,
				'num_pastes': pastes.count(),
				'your_profile': your_profile
			})
			
		path = get_template_path('profile.html')
		self.response.out.write(template.render(path, self.template_values, debug=True))