Esempio n. 1
0
def cancelRequest(request):
    params = request.data

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)

    obj, notif = Notifications.objects.get_or_create(
        fromUser=UserDetails.objects.get(userId=request.user),
        toUser=UserDetails.objects.get(userId__username=params['username']),
        notification=str(request.user.username +
                         " canceled the Friend Request from " + details))
    if (notif):
        obj.save()

    print(params)
    if (FriendsFormedDetails.objects.filter(
            user=UserDetails.objects.get(userId=request.user),
            friend_name=UserDetails.objects.get(
                userId__username=params['username'])).count() == 1):
        FriendsFormedDetails.objects.get(
            user=UserDetails.objects.get(userId=request.user),
            friend_name=UserDetails.objects.get(
                userId__username=params['username'])).delete()
        return JsonResponse({"message": "Ok Saved", "status": "200"})
    if (FriendsFormedDetails.objects.filter(
            user=UserDetails.objects.get(userId__username=params['username']),
            friend_name=UserDetails.objects.get(
                userId=request.user)).count() == 1):
        FriendsFormedDetails.objects.get(
            user=UserDetails.objects.get(userId__username=params['username']),
            friend_name=UserDetails.objects.get(userId=request.user)).delete()
        return JsonResponse({"message": "Ok Saved", "status": "200"})
    else:
        return JsonResponse({"message": "Not Found", "status": "404"})
Esempio n. 2
0
    def delete(self, request, format=None):
        params = request.data
        noteId = params['noteId']

        user_agent = get_user_agent(request)
        print(user_agent)
        details = getDeviceDetails(user_agent, request)

        try:
            for users in NotesDetails.objects.get(
                    noteId=savedNoteData.objects.get(
                        noteId=noteId)).sharedTo.all():
                print(users)
                obj, notif = Notifications.objects.get_or_create(
                    fromUser=UserDetails.objects.get(userId=request.user),
                    toUser=UserDetails.objects.get(
                        userId__username=users.sharedTo.userId.username),
                    notification=str(
                        request.user.username + " deleted note with title:- " +
                        savedNoteData.objects.get(noteId=noteId).title +
                        " that was shared With You from " + details))
                if (notif):
                    obj.save()
        except Exception as e:
            print("No Shared Users")
        try:
            savedNoteData.objects.get(noteId=noteId).delete()
            return JsonResponse({"message": "Ok Deleted", "status": "200"})
        except Exception as e:
            print(e)
            stat = status.HTTP_404_NOT_FOUND
            return Response({"message": "Not Found", "status": "404"})
Esempio n. 3
0
def submitGitHubNote(request):
    permission_classes = (IsAuthenticated, )
    parser_classes = [JSONParser]

    params = request.data

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)

    #print(params['content'])
    #print(type(params['content']))
    js = json.loads(params['content'])
    print(js)
    print(type(js))
    if ('caption' in params):
        obj, notif = savedNoteData.objects.get_or_create(
            userId=UserDetails.objects.get(userId=request.user),
            gitHubData=json.loads(params['content']),
            typeOfData="git",
            title=params['title'],
            caption=params['caption'],
            createdFrom=details,
            lastUpdated=timezone.now())
    else:
        obj, notif = savedNoteData.objects.get_or_create(
            userId=UserDetails.objects.get(userId=request.user),
            gitHubData=json.loads(params['content']),
            typeOfData="git",
            title=params['title'],
            createdFrom=details,
            lastUpdated=timezone.now())
    if notif is True:
        obj.save()
        import requests
        print(request.META.get('HTTP_AUTHORIZATION'))

        url = "https://shielded-dusk-55059.herokuapp.com/shared/shareNote/"
        res = requests.post(url,
                            data={
                                "list[]": request.data['list[]'],
                                "noteId": obj.noteId
                            },
                            headers={
                                "Authorization":
                                request.META.get('HTTP_AUTHORIZATION')
                            }).json()

        if (res['status'] == "201"):
            return JsonResponse({
                'message': "Ok Created",
                "status": "201",
                "id": obj.noteId,
                "date": obj.createdAt
            })
        else:
            return JsonResponse({'message': "Error", "status": "500"})
    else:
        return JsonResponse({'message': "Error", "status": "500"})
Esempio n. 4
0
    def post(self, request):

        user_agent = get_user_agent(request)
        print(user_agent)
        details = getDeviceDetails(user_agent, request)

        print(
            NotesDetails.objects.get(
                noteId=request.data['noteId']).likes.all())
        if (not UserDetails.objects.get(userId=request.user)
                in NotesDetails.objects.get(
                    noteId=request.data['noteId']).likes.all()):

            #Like Notif to Admin
            if (request.user.username != NotesDetails.objects.get(
                    noteId=request.data['noteId']).admin.userId.username):
                obj, notif = Notifications.objects.get_or_create(
                    fromUser=UserDetails.objects.get(userId=request.user),
                    toUser=NotesDetails.objects.get(
                        noteId=request.data['noteId']).admin,
                    notification=str(
                        request.user.username + " liked note with title:- " +
                        NotesDetails.objects.get(
                            noteId=request.data['noteId']).noteId.title +
                        " that was shared by " +
                        NotesDetails.objects.get(noteId=request.data['noteId']
                                                 ).admin.userId.username +
                        " from " + details))
                if (notif):
                    obj.save()

            #Like Notif To All Users To Whom The Note Is Shared
            for currUser in NotesDetails.objects.get(
                    noteId=request.data['noteId']).sharedTo.all():
                print(currUser.sharedTo.userId.username, request.user.username)
                if (currUser.sharedTo.userId.username !=
                        request.user.username):
                    obj1, notif1 = Notifications.objects.get_or_create(
                        fromUser=UserDetails.objects.get(userId=request.user),
                        toUser=currUser.sharedTo,
                        notification=str(
                            request.user.username +
                            " liked note with title:- " +
                            NotesDetails.objects.get(
                                noteId=request.data['noteId']).noteId.title +
                            " that was shared by " + NotesDetails.objects.get(
                                noteId=request.data['noteId']
                            ).admin.userId.username + " from " + details))
                    if (notif1):
                        obj1.save()

            obj1 = NotesDetails.objects.get(noteId=request.data['noteId'])
            obj1.likes.add(UserDetails.objects.get(userId=request.user))
            obj1.likesCount += 1
            obj1.save()
            return JsonResponse({"message": "Created", "status": "201"})
Esempio n. 5
0
    def delete(self, request):
        print("inside")
        print(request.data)

        user_agent = get_user_agent(request)
        print(user_agent)
        details = getDeviceDetails(user_agent, request)

        if (request.user.username != NotesDetails.objects.get(
                noteId=request.data['noteId']).admin.userId.username):
            #Disike Comment to Note Admin
            obj, notif = Notifications.objects.get_or_create(
                fromUser=UserDetails.objects.get(userId=request.user),
                toUser=NotesDetails.objects.get(
                    noteId=request.data['noteId']).admin,
                notification=str(
                    request.user.username +
                    " disliked the note with title:- " +
                    NotesDetails.objects.get(
                        noteId=request.data['noteId']).noteId.title +
                    " that was shared by " + NotesDetails.objects.get(
                        noteId=request.data['noteId']).admin.userId.username +
                    " from " + details))
            if (notif):
                obj.save()

        #Dislike Notif To All Users To Whom The Note Is Shared
        for currUser in NotesDetails.objects.get(
                noteId=request.data['noteId']).sharedTo.all():
            print(currUser.sharedTo.userId.username, request.user.username)
            if (currUser.sharedTo.userId.username != request.user.username):
                obj1, notif1 = Notifications.objects.get_or_create(
                    fromUser=UserDetails.objects.get(userId=request.user),
                    toUser=currUser.sharedTo,
                    notification=str(
                        request.user.username +
                        " disliked note with title:- " +
                        NotesDetails.objects.get(
                            noteId=request.data['noteId']).noteId.title +
                        " that was shared by " +
                        NotesDetails.objects.get(noteId=request.data['noteId']
                                                 ).admin.userId.username +
                        " from " + details))
                if (notif1):
                    obj1.save()

        like = NotesDetails.objects.get(noteId=request.data['noteId'])
        like.likesCount -= 1
        like.likes.remove(UserDetails.objects.get(userId=request.user))
        like.save()
        return JsonResponse({"message": "Removed", "status": "200"})
Esempio n. 6
0
def deleteSharedNote(request):
    permission_classes = (IsAuthenticated, )

    # friends=request.data.get('list')
    friends = []
    if (request.data.get('list') == None):
        friends = request.data.getlist('list[]')
        print(friends)
    else:
        friends = request.data.get('list')
    print(request.data.get('list'), request.data.get('noteId'))

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)

    try:
        for currName in friends:
            obj, notif = Notifications.objects.get_or_create(
                fromUser=UserDetails.objects.get(userId=request.user),
                toUser=UserDetails.objects.get(userId__username=currName),
                notification=str(request.user.username +
                                 " deleted a shared note from" + details))
            if (notif):
                obj.save()
            sharedNoteData.objects.get(
                noteId=savedNoteData.objects.get(
                    noteId=request.data.get('noteId')),
                sharedTo=UserDetails.objects.get(
                    userId__username=currName)).delete()
            NotesDetails.objects.get(noteId=savedNoteData.objects.get(
                noteId=request.data.get('noteId'))).comments.filter(
                    userId=UserDetails.objects.get(
                        userId__username=currName)).delete()
            [
                NotesDetails.objects.get(noteId=savedNoteData.objects.get(
                    noteId=request.data.get('noteId'))).likes.remove(user)
                for user in NotesDetails.objects.get(
                    noteId=savedNoteData.objects.get(
                        noteId=request.data.get('noteId'))).likes.filter(
                            userId=User.objects.get(username=currName))
            ]

        return JsonResponse({"message": "Ok Shared", "status": "200"})
    except Exception as e:
        print(e)
        return JsonResponse({"message": "Error", "status": "500"})
Esempio n. 7
0
def createFriend(request):
    #Get User Agent Details
    params = request.data
    print(params)

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)

    obj1, notif1 = Notifications.objects.get_or_create(
        fromUser=UserDetails.objects.get(userId=request.user),
        toUser=UserDetails.objects.get(userId__username=params['username']),
        notification=str(request.user.username +
                         " Sent You A Request at from " + details))
    if (notif1):
        obj1.save()

    if (FriendsFormedDetails.objects.filter(
            user=UserDetails.objects.get(userId=request.user),
            friend_name=UserDetails.objects.get(
                userId__username=params['username'])).count() == 0):
        obj, notif = FriendsFormedDetails.objects.get_or_create(
            user=UserDetails.objects.get(userId=request.user),
            friend_name=UserDetails.objects.get(
                userId__username=params['username']),
            access=params['access'])
        if (notif):
            obj.save()
            serializer = FriendsFormedDetailsSerializer(obj)
            print(json.dumps(serializer.data))
            return JsonResponse({
                "message": "Ok Saved",
                "status": "200",
                "friend_fromed": json.dumps(serializer.data)
            })
        else:
            return JsonResponse({"message": "Error", "status": "500"})
    else:
        return JsonResponse({"message": "Already", "status": "400"})
Esempio n. 8
0
    def post(self, request, format=None):
        parser_classes = (MultiPartParser, )
        params = request.data

        print(params)

        user_agent = get_user_agent(request)
        print(user_agent)
        details = getDeviceDetails(user_agent, request)

        if ('caption' in params):
            obj, notif = savedNoteData.objects.get_or_create(
                userId=UserDetails.objects.get(userId=request.user),
                noteData=params['content'],
                typeOfData="note",
                title=params['title'],
                caption=params['caption'],
                createdFrom=details,
                showUpImg=params['imgData'],
                lastUpdated=timezone.now())
        else:
            obj, notif = savedNoteData.objects.get_or_create(
                userId=UserDetails.objects.get(userId=request.user),
                noteData=params['content'],
                typeOfData="note",
                title=params['title'],
                createdFrom=details,
                showUpImg=params['imgData'],
                lastUpdated=timezone.now())
        if notif is True:
            obj.save()
            return JsonResponse({
                'message': "Ok Created",
                "status": "201",
                "id": obj.noteId,
                "date": obj.createdAt
            })
        else:
            return JsonResponse({'message': "Error", "status": "500"})
Esempio n. 9
0
    def post(self, request):

        user_agent = get_user_agent(request)
        print(user_agent)
        details = getDeviceDetails(user_agent, request)

        #Comment Notif To Note Admin
        if (request.user.username != NotesDetails.objects.get(
                noteId=request.data['noteId']).admin.userId.username):
            obj, notif = Notifications.objects.get_or_create(
                fromUser=UserDetails.objects.get(userId=request.user),
                toUser=NotesDetails.objects.get(
                    noteId=request.data['noteId']).admin,
                notification=str(
                    request.user.username + " commented '" +
                    request.data['comment'][0:10] +
                    "...' on the note with title:- " +
                    NotesDetails.objects.get(
                        noteId=request.data['noteId']).noteId.title +
                    " that was shared by " + NotesDetails.objects.get(
                        noteId=request.data['noteId']).admin.userId.username +
                    " from " + details))
            if (notif):
                obj.save()

        #Comment Notif To All Users To Whom The Note Is Shared
        for currUser in NotesDetails.objects.get(
                noteId=request.data['noteId']).sharedTo.all():
            print(currUser.sharedTo.userId.username, request.user.username)
            if (currUser.sharedTo.userId.username != request.user.username):
                obj1, notif1 = Notifications.objects.get_or_create(
                    fromUser=UserDetails.objects.get(userId=request.user),
                    toUser=currUser.sharedTo,
                    notification=str(
                        request.user.username + " commented '" +
                        request.data['comment'][0:10] +
                        "...' on the note with title:- " +
                        NotesDetails.objects.get(
                            noteId=request.data['noteId']).noteId.title +
                        " that was shared by " +
                        NotesDetails.objects.get(noteId=request.data['noteId']
                                                 ).admin.userId.username +
                        " from " + details))
                if (notif1):
                    obj1.save()

        comment, notif = CommentsOnNotes.objects.get_or_create(
            noteId=savedNoteData(noteId=request.data['noteId']),
            userId=UserDetails.objects.get(userId=request.user),
            comment=request.data['comment'])
        if (notif):
            comment.save()
            obj = NotesDetails.objects.get(noteId=request.data['noteId'])
            obj.comments.add(comment)
            obj.save()
            return JsonResponse({
                "message": "Created",
                "status": "201",
                "generatedId": comment.commentId
            })
        else:
            return JsonResponse({"message": "Error", "status": "500"})
Esempio n. 10
0
def shareNote(request):
    permission_classes = (IsAuthenticated, )

    print(request.POST)
    print("\n\n")
    print(request.data)
    friends = []
    if (request.data.get('list') == None):
        friends = request.data.getlist('list[]')
        print(friends)
    else:
        friends = request.data.get('list')
    print(request.data.get('list'), request.data.get('noteId'))

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)
    '''May Fail in cases like if a user changes his/her username
    sharedNoteData.objects.bulk_create(
        [sharedNoteData(noteId=savedNoteData.objects.get(noteId=request.POST.get('noteId')), admin=User.objects.get(username=request.user.username), sharedTo=User.objects.get(username=currName)) for currName in friends]
     ) '''
    try:
        for currName in friends:

            obj, notif = Notifications.objects.get_or_create(
                fromUser=UserDetails.objects.get(userId=request.user),
                toUser=UserDetails.objects.get(userId__username=currName),
                notification=str(request.user.username +
                                 " shared a note With You from" + details))
            if (notif):
                obj.save()

            obj, notif = sharedNoteData.objects.get_or_create(
                noteId=savedNoteData.objects.get(
                    noteId=request.data.get('noteId')),
                sharedTo=UserDetails.objects.get(userId__username=currName),
                sharedFrom=details)
            if (notif):
                obj.save()
                if (NotesDetails.objects.filter(
                        noteId=savedNoteData.objects.get(
                            noteId=request.data.get('noteId'))).count() == 0):
                    obj1, notif1 = NotesDetails.objects.get_or_create(
                        noteId=savedNoteData.objects.get(
                            noteId=request.data.get('noteId')),
                        admin=UserDetails.objects.get(userId=request.user))
                    if (notif1):
                        obj1.save()
                        obj1.sharedTo.add(obj)
                        obj1.save()
                        return JsonResponse({
                            "message": "Ok Shared",
                            "status": "201"
                        })
                    else:
                        return JsonResponse({
                            "message": "Error",
                            "status": "500"
                        })
                else:
                    getNote = NotesDetails.objects.get(
                        noteId=savedNoteData.objects.get(
                            noteId=request.data.get('noteId')))
                    getNote.sharedTo.add(obj)
                    getNote.save()
                    return JsonResponse({
                        "message": "Ok Shared",
                        "status": "201"
                    })
        return JsonResponse({"message": "Ok Shared", "status": "201"})
    except Exception as e:
        print(e)
        return JsonResponse({"message": "Error", "status": "500"})
Esempio n. 11
0
def acceptFriend(request):
    params = request.data
    print(params)

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)

    obj, notif = Notifications.objects.get_or_create(
        fromUser=UserDetails.objects.get(userId=request.user),
        toUser=UserDetails.objects.get(userId__username=params['username']),
        notification=str(request.user.username +
                         " Accepted Your Friend Request from " + details))
    if (notif):
        obj.save()

    if (FriendsFormedDetails.objects.filter(
            user=UserDetails.objects.get(userId__username=params['username']),
            friend_name=UserDetails.objects.get(
                userId=request.user)).count() == 1):
        print("inside none")
        friend = FriendsFormedDetails.objects.get(
            user=UserDetails.objects.get(userId__username=params['username']),
            friend_name=UserDetails.objects.get(userId=request.user))
        friend.friend_or_Request = True
        friend.save()
        print("saved")
        if (UserFriends.objects.filter(userId=UserDetails.objects.get(
                userId=request.user)).count() == 0):
            obj1, notif1 = UserFriends.objects.get_or_create(
                userId=UserDetails.objects.get(userId=request.user))
            if (notif1):
                obj1.save()
                obj1.friends.add(friend)
                obj1.save()
                print("saved1")
                obj11, notif11 = UserFriends.objects.get_or_create(
                    userId=UserDetails.objects.get(
                        userId__username=params['username']))
                if (notif11):
                    obj11.save()
                    obj11.friends.add(friend)
                    obj11.save()
                    print("saved2")
                    serializer = FriendsFormedDetailsSerializer(friend)
                    print(json.dumps(serializer.data))
                    return JsonResponse({
                        "message":
                        "Ok Saved",
                        "status":
                        "201",
                        "friend_fromed":
                        json.dumps(serializer.data)
                    })
                    #return JsonResponse({"message":"Ok Saved", "status": "201"})

                else:
                    return JsonResponse({"message": "Error", "status": "500"})
            else:
                return JsonResponse({"message": "Error", "status": "500"})
        else:
            getUser = UserFriends.objects.get(userId=UserDetails.objects.get(
                userId=request.user))
            getUser.friends.add(friend)
            getUser.save()
            if (UserFriends.objects.filter(userId=UserDetails.objects.get(
                    userId__username=params['username'])).count() == 0):
                getUser1, notif1 = UserFriends.objects.get_or_create(
                    userId=UserDetails.objects.get(
                        userId__username=params['username']))
                if (notif1):
                    getUser1.save()
                    getUser1.friends.add(friend)
                    getUser1.save()
                    serializer = FriendsFormedDetailsSerializer(friend)
                    print(json.dumps(serializer.data))
                    return JsonResponse({
                        "message":
                        "Ok Saved",
                        "status":
                        "201",
                        "friend_fromed":
                        json.dumps(serializer.data)
                    })
                    #return JsonResponse({"message":"Ok Saved", "status": "201"})
                else:
                    return JsonResponse({"message": "Error", "status": "500"})
            else:
                getUser1 = UserFriends.objects.get(
                    userId=UserDetails.objects.get(
                        userId__username=params['username']))
                getUser1.friends.add(friend)
                getUser1.save()
                serializer = FriendsFormedDetailsSerializer(friend)
                print(json.dumps(serializer.data))
                return JsonResponse({
                    "message":
                    "Ok Saved",
                    "status":
                    "201",
                    "friend_fromed":
                    json.dumps(serializer.data)
                })
                #return JsonResponse({"message":"Ok Saved", "status": "201"})

    else:
        return JsonResponse({"message": "Not Found", "status": "404"})
Esempio n. 12
0
def removeFriend(request):
    params = request.data
    print(params)

    user_agent = get_user_agent(request)
    print(user_agent)
    details = getDeviceDetails(user_agent, request)

    obj, notif = Notifications.objects.get_or_create(
        fromUser=UserDetails.objects.get(userId=request.user),
        toUser=UserDetails.objects.get(userId__username=params['username']),
        notification=str(request.user.username + " unfriended you from " +
                         details))
    if (notif):
        obj.save()

    try:
        if (FriendsFormedDetails.objects.filter(
                user=UserDetails.objects.get(userId=request.user),
                friend_name=UserDetails.objects.get(
                    userId__username=params['username'])).count() == 1):
            FriendsFormedDetails.objects.get(
                user=UserDetails.objects.get(userId=request.user),
                friend_name=UserDetails.objects.get(
                    userId__username=params['username'])).delete()

        if (FriendsFormedDetails.objects.filter(
                user=UserDetails.objects.get(
                    userId__username=params['username']),
                friend_name=UserDetails.objects.get(
                    userId=request.user)).count() == 1):
            FriendsFormedDetails.objects.get(
                user=UserDetails.objects.get(
                    userId__username=params['username']),
                friend_name=UserDetails.objects.get(
                    userId=request.user)).delete()

        #Deleting Shared To From Notes Details For Current Both User and his friend
        sharedNoteData.objects.filter(
            sharedTo=UserDetails.objects.get(userId=request.user),
            noteId__userId=UserDetails.objects.get(
                userId__username=params['username'])).delete()
        sharedNoteData.objects.filter(sharedTo=UserDetails.objects.get(
            userId__username=params['username']),
                                      noteId__userId=UserDetails.objects.get(
                                          userId=request.user)).delete()

        #Deleting Comments From Notes Details For Current Both User and his friend
        [
            CommentsOnNotes.objects.get(noteId=likes['noteId']).delete()
            for likes in NotesDetails.objects.filter(
                admin=UserDetails.objects.get(userId=request.user),
                sharedTo__in=sharedNoteData.objects.filter(
                    sharedTo__userId__username=params['username'])).values(
                        'noteId', 'comments')
        ]
        [
            CommentsOnNotes.objects.get(noteId=likes['noteId']).delete()
            for likes in NotesDetails.objects.filter(
                admin=UserDetails.objects.get(
                    userId__username=params['username']),
                sharedTo__in=sharedNoteData.objects.filter(
                    sharedTo__userId=request.user)).values(
                        'noteId', 'comments')
        ]

        #Deleting Likes From Notes Details For Current Both User and his friend
        [
            NotesDetails.objects.get(noteId=likes['noteId']).likes.remove(
                likes['likes']) for likes in NotesDetails.objects.filter(
                    admin=UserDetails.objects.get(userId=request.user),
                    sharedTo__in=sharedNoteData.objects.filter(
                        sharedTo__userId__username=params['username'])).values(
                            'noteId', 'likes')
        ]
        [
            NotesDetails.objects.get(noteId=likes['noteId']).likes.remove(
                likes['likes'])
            for likes in NotesDetails.objects.filter(
                admin=UserDetails.objects.get(
                    userId__username=params['username']),
                sharedTo__in=sharedNoteData.objects.filter(
                    sharedTo__userId=request.user)).values('noteId', 'likes')
        ]

        return JsonResponse({"message": "Deleted", "status": "200"})
    except Exception as e:
        print(e)
        return JsonResponse({"message": "Not Found", "status": "404"})