Ejemplo n.º 1
0
def show_interest(request):
	if request.method == "POST" and request.is_ajax():
		print "AJAX------------------------------------SHOW INTEREST"
		context = {}
		#----GET VARIABLES---#
		user1 = request.user
		user1_profile = Profile.objects.get(user=user1)		
		user1_uuid = user1_profile.id
		user2_uuid = request.POST['user2_uuid']
		user2_profile = Profile.objects.get(id=user2_uuid)
		user2 = user2_profile.user
		#----INTERESTS ARE DIRECTED GRAPHS----#
		friends_object = Friends(user1=user1,user2=user2,status = "I",user1_uuid=user1_uuid,user2_uuid=user2_uuid)
		friends_object.save()
		message = user1_profile.first_name + " " + user1_profile.last_name + " shown interest on you"
		notification_object = Notification(
											user1=user1,
											user2=user2,
											message=message,
											read=False,
											notification_type="SI",
											target_id=friends_object.friends_id,
											user1_uuid=user1_uuid,
											user2_uuid=user2_uuid
											)
		notification_object.save()					
		print user2_uuid;
		notification_delete = request.POST['notification_delete']
		if notification_delete == "ok":
			notification_id = request.POST['notification_id']
			notification_object_delete = Notification.objects.get(notification_id=notification_id)
			notification_object_delete.delete()	

		return render(request,'error.html',context)
	return render(request,'error.html',{})
def register(request):
    if request.method == 'POST':
        # return HttpResponse(request.POST.get('password1'))
        form = UserRegistrationForm(request.POST)
        # profileForm = UserUpdateForm(request.POST)
        if form.is_valid():
            userTable = models.User()
            userTable.first_name = request.POST['first_name']
            userTable.last_name = request.POST['last_name']
            userTable.username = request.POST['username']
            userTable.email = request.POST['email']
            userTable.password = make_password(request.POST.get('password1'))
            userTable.save()

            friendTable = Friends()
            friendTable.current_user = userTable
            friendTable.save()

            username = form.cleaned_data.get('username')
            messages.success(
                request,
                f'Your account has been created! You are now able to login!')
            messages.warning(
                request,
                f'Please login to your account and update profile using [Edit Profile] option!'
            )
            return redirect('login')
    else:
        form = UserRegistrationForm()
        # profileForm = UserUpdateForm()
    return render(request, 'user/registration.html', {'form': form})
Ejemplo n.º 3
0
def show_messaging(request):
	my_friends = getMyFriendsMessaging(request)
	my_uuid = Profile.objects.get(user=request.user).id
	import pdb; pdb.set_trace()
	testz = Friends.test()
	context = {"my_friends":my_friends,"my_uuid":my_uuid}
	return render(request,"show_messaging.html",context)
Ejemplo n.º 4
0
def friends_relation(request, operation, pk):
    friend = User.objects.get(pk=pk)
    if operation == 'req':
        FriendRequest.make_friend_request(request.user, friend)
    elif operation == 'rej':
        FriendRequest.reject_friend_request(request.user, friend)
    elif operation == 'add':
        Friends.make_friend_request_accept(request.user, friend)
        Friends.make_friend_request_accept(friend, request.user)
    elif operation == 'remove':
        Friends.lose_friend(request.user, friend)
        Friends.lose_friend(friend, request.user)
    return redirect('home2')
Ejemplo n.º 5
0
def add(request):
    if request.is_ajax() or True:
        try:
            friend = User.objects.get(pk=request.GET["id"])
        except User.DoesNotExist:
            raise Http404

        try:
            Friends.objects.get(Q(user=request.user, friend=friend) | Q(user=friend, friend=request.user))
        except Friends.DoesNotExist:
            # Save new request
            f = Friends(user=request.user, friend=friend)
            f.save()

            # Send notification
            NotificationSystem.create(friend, const.NotifConst.FRIEND_REQ)

            return HttpResponse("OK")
        else:
            return HttpResponse("ERR")
Ejemplo n.º 6
0
 def create(cls, validated_data):
     # create friend
     
     try:
         author = validated_data["author"]   # person who received the request
         friend = validated_data["friend"]   # person who made the request
         
         if (Friends.objects.filter(author=author, friend=friend).exists()):
             # the relation already exists in the database
             raise ValueError("Author is already friends with this friend")
         
         if ((User.objects.filter(id=author).exists()) and (User.objects.filter(id=friend).exists())):
             # verify users (author + friend) exists
             authorUser = User.objects.get(id=author)
             friendUser = User.objects.get(id=friend)
             friend1 = Friends(author=authorUser, friend=friendUser)
             friend2 = Friends(author=friendUser, friend=authorUser)
             friend1.save()
             friend2.save()
     except:
         raise RuntimeError("Unable to create friend")