示例#1
0
def add_friend(request):
	if not request.user.is_authenticated():
		return redirect(gethome())
	if request.method != 'POST':
		return redirect(gethome())
	else:			
		print "HELLO I AM AT AN AJAX CALL AT FRIENDS.VIEW.add_friend-----------------------------------------------------"
		print request.POST
		if "user2" in request.POST:
			user2_id = request.POST["user2"] 
			Profile2_object = Profile.objects.filter(id=user2_id)
			user2 = Profile2_object[0].user
			user1 = request.user #user who clicked add friend ==> userFrom

			message = Profile2_object[0].first_name + " " + Profile2_object[0].last_name + " wants to be friends with you"
			if checkFriendExisted(user1,user2) == True:
				return redirect(gethome())
			#-------------BETA-------------------------------------#
			user2_uuid = Profile2_object[0].id
			user1_uuid = Profile.objects.filter(user=user1)[0].id
			#-------------BETA-------------------------------------#
			friend_object = Friends(user1=user1,user2=user2,status = "P",user1_uuid=user1_uuid,user2_uuid=user2_uuid)
			friend_object.save()
			if(checkNotificationExisted(user1,user2,"F") == False):
				notification_object = Notification( user1=user1,
													user2=user2,
													message=message,
													read=False,
													notification_type="FR",
													target_id=friend_object.friends_id,
													user1_uuid=user1_uuid,
													user2_uuid=user2_uuid)
				notification_object.save()
			print "-------------DONE-----------------"
		return redirect(gethome())
示例#2
0
def show_user(request):
	if request.user.is_authenticated():
		if request.method == 'GET':
			profile_id = request.GET['profile_id']
			target_profile = Profile.objects.get(id=profile_id) #---> GET TARGET PROFILE
			context = {"profile":target_profile,"interest":"none"}			
#			friends_status = getStatus(request.user,profile.user) #--OLD CODE
			my_user = request.user
			my_profile = Profile.objects.get(user=my_user)
			user1_uuid = my_profile.id
			user2_uuid = target_profile.id 
			#------------------------------FRIENDS CODE----------------------------------------#
			friends_object12 = Friends.manager.get_object_from(user1_uuid,user2_uuid)
			friends_object21 = Friends.manager.get_object_from(user2_uuid,user1_uuid)
			if friends_object12 is not None:
				if friends_object21 is not None:
					if friends_object12.status == "I" and friends_object21.status =="I":
						context.update( {"interest":"mutual","roomate_id":"none"} )
				else:
					if friends_object12.status == "I":
						context.update({"interest":"pending"})
			else:
				if friends_object21 is not None:
					if friends_object21.status == "I":
						context.update({"interest":"interested"})
			#------------------------------FRIENDS CODE----------------------------------------#
			#------------------------------ROOMATE CODE----------------------------------------#
			roomate_object = Roomate.manager.get_object_from(user1_uuid,user2_uuid)
			print roomate_object			
			if roomate_object is not None:
				roomate_status = roomate_object.status
				if roomate_status == 'P': #--PENDING
					if user1_uuid == roomate_object.user1_uuid:
						context.update({"interest":"roomate_waiting","roomate_id":"none"})	
					else:
						context.update({"interest":"roomate_pending","roomate_id":roomate_object.roomate_id})
				elif roomate_status == 'R': #--ROOMATES
					context.update({"interest":"roomates"})


			#------------------------------ROOMATE CODE----------------------------------------#
			# if friends_status == 'P':
			# 	friends_object = getFriendsObject(request.user,profile.user)				
			# 	friends_id = friends_object.friends_id
			# 	notification_object = Notification.objects.get(target_id=friends_id)
			# 	user1_uuid = notification_object.user1_uuid
			# 	user2_uuid = notification_object.user2_uuid
			# 	my_uuid = Profile.objects.get(user=request.user).id
			# 	this_id = notification_object.notification_id
			# 	additional_context = {"target_id":friends_id,
			# 						  "my_uuid":my_uuid,
			# 						  "user1_uuid":user1_uuid,
			# 						  "user2_uuid":user2_uuid,
			# 						  "this_id":this_id,
			# 						  "friends_object":friends_object
			# 						  }
			# 	context.update(additional_context)
			print context
			return render(request,'show_user.html',context)
	return redirect(gethome())
示例#3
0
def change_friend_status(request):
	if not request.user.is_authenticated():
		return redirect(gethome())

	if request.method != 'POST':
		print "NOT POST-----------------"
		return redirect(gethome())
	else:
		print "CHANGE REQUEST ENTER AJAX CALL--------------------------"
		print request.POST
		notification_id = request.POST['this_id']
		notification_object = Notification.objects.filter(notification_id=notification_id)
		response_type = str(request.POST['type']) 
		if "delete_notification" == response_type:
			print "DELETe NOTIFICATION--------------------AJAX------------------"			
			notification_object.delete()
			return redirect(gethome())

		target_id = request.POST['target_id']
		friend_object = Friends.objects.filter(friends_id=target_id)				
		#-------------BETA-------------------------------------#			
		user1_uuid = request.POST['user1_uuid']
		user2_uuid = request.POST['user2_uuid']
		#-------------BETA-------------------------------------#	
		if "accept" == response_type:
			print "ACCEPT-------------------AJAX------------------"
			friend_object.update(status="F")			
			notification_object.delete()
			#-------------BETA-------------------------------------#			
			profile1 = Profile.objects.get(id=user1_uuid)
			profile2 = Profile.objects.get(id=user2_uuid)
			#-------------BETA-------------------------------------#
			message =  str(profile2.first_name) + " " +str(profile2.last_name) +" " +"HAVE BECOME FRIENDS WITH YOU"
			accept_notification = Notification( user1=profile2.user,
												user2=profile1.user,
												message=message,
												user1_uuid=user2_uuid,
												user2_uuid=user1_uuid,
												notification_type="FA")
			accept_notification.save()
		elif "ignore" == response_type:
			print "IGNORE-------------------AJAX------------------"
			friend_object.delete()						
			notification_object.delete()			
		elif "block" == response_type:
			print "BLOCK--------------------AJAX------------------"
	return redirect(gethome())
示例#4
0
def edit_profile(request):
	if request.user.is_authenticated():
		my_profile = Profile.objects.filter(user=request.user)
		edit = EditForm(request.POST or None,request.FILES or None ,instance = my_profile[0])		
		if edit.is_valid():
			#print "EDIT PROFILE--------------------------------------------"
			instance = edit.save(commit=False)
			instance.save()
		context = {"profile":my_profile[0],"edit":edit}
		return render(request,'edit_profile.html',context)
	else:
		return redirect(gethome())
示例#5
0
def first_time_user(request):
	if request.user.is_authenticated():
		myForm = ProfileForm(request.POST or None)
		if request.method == "POST" and myForm.is_valid():
			first_name = myForm.data['first_name']
			middle_name = myForm.data['middle_name']
			last_name = myForm.data['last_name']
			nationality =myForm.data['nationality']
			gender = myForm.data['gender']
			myProfile = Profile.objects.select_for_update().filter(user=request.user)
			myProfile.update(first_name=first_name,middle_name=middle_name,last_name=last_name)
			return redirect(gethome())
		else:
			context = {"form":myForm}
			return render(request,'first_time_user.html',context)
	else:
		return render(request,'error_login.html',{})
示例#6
0
def logout_view(request):
	logout(request)
	return redirect(gethome())