Beispiel #1
0
def newsfeed(request):

    likers = Likers.objects.filter(liker=request.user)

    whichuser = request.user


    if request.method == "POST":

        form = StatusForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            print post.author
            post.save()
            return redirect(newsfeed)

    else:

        form = StatusForm()


    winks = Wink.objects.filter(receiver=request.user)

    crushes = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).values_list('crush', flat=True)

    crushes2 = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).values_list('creator', flat=True)


    posts = Status.objects.order_by('-created_date').filter(Q(author_id__in=crushes) | Q(author_id__in=crushes2) | Q(author_id=request.user))


    return render(request, 'newsfeed.html', {'whichuser': whichuser, 'likers': likers, 'form': form, 'posts': posts, 'winks': winks})
Beispiel #2
0
def profile(request, id=None):






    #get everything that request.user has liked and if the status == to a liked status then change the html

    likers = Likers.objects.filter(liker=request.user)



    if request.method == "POST":

        form = StatusForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            print post.author
            post.save()
            return redirect(profile)


    if id: #if navigating to another page


        whichuser = User.objects.get(pk=id)
        switch = True
        posts = Status.objects.filter(author_id=id).order_by('-created_date')

        #Queries a list of all the crushes of the users page navigated to and excludes to current authorised user
        crushes = Crush.objects.filter(Q(creator=whichuser) | Q(crush=whichuser)).exclude(Q(creator=request.user) | Q(crush=request.user))

        #Queries the crush databse to check if the profile navigated to is already a friend or not.
        if Crush.objects.filter(creator=request.user, crush=whichuser) or Crush.objects.filter(creator=whichuser, crush=request.user):

            isprofilefriend = True

        else:

            isprofilefriend = False



    else: #if navigating to users page




        whichuser = request.user
        switch = False
        crushes = Crush.objects.filter(Q(creator=whichuser) | Q(crush=whichuser))
        isprofilefriend = False
        posts = Status.objects.filter(author_id=request.user).order_by('-created_date')

    statusform = StatusForm()
    profilepicform = ProfilePictureForm()

    return render(request, 'profile.html', {'likers': likers, 'posts': posts, 'profilepicform': profilepicform, 'statusform': statusform, 'whichuser': whichuser, 'switch': switch, 'crushes': crushes, 'isprofilefriend': isprofilefriend})
Beispiel #3
0
def newsfeed(request):

    first_feed = User.objects.filter(pk=request.user.id).values_list('first_feed', flat=True)

    user_first_feed = first_feed[0]

    if request.user.date_joined.date() == request.user.last_login.date() and user_first_feed:

        User.objects.filter(pk=request.user.id).update(first_feed = False)

        Notification.objects.create(message="All your notifictions will appear here! ", user=request.user)

        print '1'

        first_time_login = 1

    else:

        print '2'

        first_time_login = 2

    likers = Likers.objects.filter(liker=request.user)

    whichuser = request.user


    if request.method == "POST":

        form = StatusForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.wall = request.user
            print post.author
            post.save()
            return redirect(newsfeed)

    else:

        form = StatusForm()


    winks = Wink.objects.filter(receiver=request.user)

    crushes = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).values_list('crush', flat=True)

    crushes2 = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).values_list('creator', flat=True)

    crushcount = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).count()
    statuscount = Status.objects.filter(author_id=request.user).count()
    posts = Status.objects.order_by('-created_date').filter(Q(author_id__in=crushes) | Q(author_id__in=crushes2) | Q(author_id=request.user))


    return render(request, 'newsfeed.html', {'crushcount': crushcount, 'statuscount': statuscount ,'first_time_login': first_time_login,'whichuser': whichuser, 'likers': likers, 'form': form, 'posts': posts, 'winks': winks})
Beispiel #4
0
def wall(request, id):

    whichuser = User.objects.get(pk=id)

    if request.method == "POST":

        form = StatusForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.wall = whichuser
            print post.author
            post.save()
            return redirect(profile, id=id)
Beispiel #5
0
def wall(request, id):

    whichuser = User.objects.get(pk=id)

    if request.method == "POST":

        form = StatusForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.wall = whichuser
            print post.author
            post.save()
            Notification.objects.create(message=request.user.first_name + ' ' + request.user.last_name + " posted on your wall", user=whichuser)
            #Notification.objects.create(message=creator.first_name + ' ' + creator.last_name + " added you!", user=crush)

            return redirect(profile, id=id)
Beispiel #6
0
def profile(request, id=None):

    sent = 2

    first_login = User.objects.filter(pk=request.user.id).values_list('first_login', flat=True)

    user_first_login = first_login[0]

    if request.user.date_joined.date() == request.user.last_login.date() and user_first_login:


        User.objects.filter(pk=request.user.id).update(first_login = False)

        #Notification.objects.create(message="Welcome " + request.user.first_name + "!", user=request.user)

        print '1'

        first_time_login = 1

    else:

        print '2'

        first_time_login = 2

    unlock = False

    fleekyvalue = 0


    #get everything that request.user has liked and if the status == to a liked status then change the html

    likers = Likers.objects.filter(liker=request.user)

    notifications = Notification.objects.filter(user=request.user, viewed=False)





    if request.method == "POST":

        form = StatusForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.wall = request.user
            print post.author
            post.save()
            return redirect(profile)


    if id: #if navigating to another page

        first_otherprofile = User.objects.filter(pk=request.user.id).values_list('first_otherprofile', flat=True)


        user_first_login2 = first_otherprofile[0]

        if request.user.date_joined.date() == request.user.last_login.date() and user_first_login2:

            User.objects.filter(pk=request.user.id).update(first_otherprofile = False)

            first_time_login = 3


        users = None



        whichuser = User.objects.get(pk=id)

        whichuser.page_views += 1

        whichuser.save()


        switch = True
        posts = Status.objects.filter(Q(author_id=id) | Q(wall_id=id)).order_by('-created_date')

        #Queries a list of all the crushes of the users page navigated to and excludes to current authorised user
        crushes = Crush.objects.filter(Q(creator=whichuser) | Q(crush=whichuser)).exclude(Q(creator=request.user) | Q(crush=request.user)) #should be and?

        if Wink.objects.filter(initiator=request.user, receiver=whichuser):

            sent = 1

        #Queries the crush databse to check if the profile navigated to is already a friend or not.
        if Crush.objects.filter(creator=request.user, crush=whichuser) or Crush.objects.filter(creator=whichuser, crush=request.user):



            #checks if the relationships points are >= 3. If true, it unlocks a new feature on the page.
            if Crush.objects.filter(creator=request.user, crush=whichuser):

                points1 = Crush.objects.get(creator=request.user, crush=whichuser)

                fleekyvalue = points1.points

                if points1.points >= 5:

                    unlock = True

            elif Crush.objects.filter(creator=whichuser, crush=request.user):

                points2 = Crush.objects.get(creator=whichuser, crush=request.user)

                fleekyvalue = points2.points

                if points2.points >= 5:

                    unlock = True



            isprofilefriend = True

        else:

            isprofilefriend = False





    else: #if navigating to users page

        users = None


        mycrushes = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).values_list('crush', flat=True)

        mycrushes2 = Crush.objects.filter(Q(creator=request.user) | Q(crush=request.user)).values_list('creator', flat=True)


        if request.user.seeking == None:

            print '5'

            users = User.objects.order_by('?').exclude(Q(id=request.user.id) | Q(id__in=mycrushes) | Q(id__in=mycrushes2))[:4] #potential to slow down server big time, find alternative to '?'




        #Gay man seeking man
        if request.user.seeking == 'Male' and request.user.gender == 'Male':

            number_users = User.objects.filter(gender='Male').count()

            users = User.objects.filter(Q(gender='Male') & Q(seeking='Male')).exclude(Q(id=request.user.id) | Q(id__in=mycrushes) | Q(id__in=mycrushes2))[:4]



        #Straight man seeking woman
        elif request.user.seeking == 'Female' and request.user.gender == 'Male':

            number_users = User.objects.filter(gender='Female').count()

            users = User.objects.filter(Q(gender='Female') & Q(seeking='Male')).exclude(Q(id=request.user.id) | Q(id__in=mycrushes) | Q(id__in=mycrushes2))[:4]


        #Straight woman seeking man
        elif request.user.seeking == 'Male' and request.user.gender == 'Female':

            number_users = User.objects.filter(gender='Male').count()

            users = User.objects.filter(Q(gender='Male') & Q(seeking='Female')).exclude(Q(id=request.user.id) | Q(id__in=mycrushes) | Q(id__in=mycrushes2))[:4]


        #Gay woman seeking woman
        elif request.user.seeking == 'Female' and request.user.gender == 'Female':

            number_users = User.objects.filter(gender='Female').count()

            users = User.objects.filter(Q(gender='Female') & Q(seeking='Female')).exclude(Q(id=request.user.id) | Q(id__in=mycrushes) | Q(id__in=mycrushes2))[:4]




        whichuser = request.user
        switch = False
        crushes = Crush.objects.filter(Q(creator=whichuser) | Q(crush=whichuser)).order_by('-points')
        isprofilefriend = False
        posts = Status.objects.filter(Q(author_id=request.user) | Q(wall_id=request.user)).order_by('-created_date')

    statusform = StatusForm()
    profilepicform = ProfilePictureForm()


    return render(request, 'profile.html', {'sent': sent, 'first_time_login': first_time_login, 'users': users, 'fleekyvalue': fleekyvalue, 'unlock': unlock,'notifications':notifications, 'likers': likers, 'posts': posts, 'profilepicform': profilepicform, 'statusform': statusform, 'whichuser': whichuser, 'switch': switch, 'crushes': crushes, 'isprofilefriend': isprofilefriend})