Exemplo n.º 1
0
def message_unread(request):
    
     if not request.user.is_authenticated():
        return HttpResponseRedirect("/login/")
        
     user_ = request.user
     if request.POST:
         if request.POST.has_key("commentbox"):
            com_con = request.POST["commentbox"]
            no_id =  request.POST["no_id"]
            noti = Notition.objects.get(id = int(no_id))
            noti.status = "3"
            noti.save()
            new_comment = Comment(
                user = user_,
                content = com_con,
                tweet = noti.to_tweet
            )
            new_comment.save()
            new_notition = Notition(
                f_comm = new_comment,
                t_comm = noti.f_comm,
                to_tweet = noti.to_tweet,
                to_user = noti.f_comm.user,
                noti_type = "2",
                status = "1"
            )
            new_notition.save()
        
     user_ = request.user
     friends = []
     for friendship in Friendship.objects.filter(to_user = user_):
         friends.append(friendship.from_user)
     for friendship in Friendship.objects.filter(from_user = user_):
        friends.append(friendship.to_user)
     friend_num = len(friends)
     tweet_num = Tweet.objects.filter(user = user_).count()
     notitions = Notition.objects.filter(to_user = user_).filter( status = "1")
     for noti in notitions:
         noti.status = "2"
         noti.save()
     print "OK"
     c = Context({"notitions": notitions,\
                  "notition_num": 0,
                  "invitation_num":FriendshipInvitation.objects.filter(to_user = user_).filter( status = "1").count(),\
                  "friend_num":friend_num, "friends" :friends,"current_user" : user_,"tweet_num":tweet_num})
     return render_to_response("message.html", c)
Exemplo n.º 2
0
def home_friends(request):
    '''##'''
    pageItemNum = 3
    current_page = 0
    '''##'''
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/login/")
    
    user_ = request.user
    if request.POST:
        if request.POST.has_key("inputbox"):
            tweet_con = request.POST["inputbox"]
            new_tweet = Tweet(
                user = user_,
                content = tweet_con
            )
            new_tweet.save()
        if request.POST.has_key("commentbox"):
            com_con = request.POST["commentbox"]
            tweet_id =  request.POST["id"]
            '''##'''
            current_page = int(request.POST['page'])
            '''##'''
            to_tweet = Tweet.objects.get(id = int(tweet_id))
            new_comment = Comment(
                user = user_,
                content = com_con,
                tweet = to_tweet
            )
            new_comment.save()
    if request.GET:
        if request.GET.has_key("search"):
            friends = []
            tweet_list = []
            for friendship in Friendship.objects.filter(to_user = user_):
                friends.append(friendship.from_user)
            for friendship in Friendship.objects.filter(from_user = user_):
                friends.append(friendship.to_user)
            friend_num = len(friends)
            s_user = get_object_or_404(User, username = request.GET["search"])
            for tweet in Tweet.objects.filter(user = s_user):
                new_tweet = Tweets(tweet)
                new_tweet.comments = list(tweet.comment_set.all())
                new_tweet.com_num = tweet.comment_set.all().count()
                new_tweet.isf = True
                tweet_list.append(new_tweet)
            tweet_list.sort(key=lambda x:x.tweet.tweet_time, reverse = True)
            tweet_num = Tweet.objects.filter(user = user_).count()
            '''##'''
            page_num = len(tweet_list)/pageItemNum
            if request.GET.has_key('page'):
               current_page = int(request.GET['page'])
            '''##'''
            no_num = Notition.objects.filter(to_user = user_).filter(status = "1").count()
            c = Context({"tweet_list": tweet_list[current_page*pageItemNum:(1 + current_page)*pageItemNum],\
            "friends" :friends, "current_user" : user_, \
            #
            'current_page': current_page,\
            'page_num': page_num,\
            #
            "friend_num":friend_num, "tweet_num":tweet_num, \
            "invitation_num":FriendshipInvitation.objects.filter\
            (to_user = request.user).filter( status = "1").count(),
            "notition_num": no_num})
            return render_to_response("home3.html", c)
        
    friends = []
    tmp_tweet_list = []
    tweet_list = []
    for friendship in Friendship.objects.filter(to_user = user_):
        friends.append(friendship.from_user)
        tmp_tweet_list.extend(friendship.from_user.tweet_set.all())
    for friendship in Friendship.objects.filter(from_user = user_):
        friends.append(friendship.to_user)
        tmp_tweet_list.extend(friendship.to_user.tweet_set.all())
        
    for tweet in tmp_tweet_list:
        new_tweet = Tweets(tweet)
        new_tweet.comments = list(tweet.comment_set.all())
        new_tweet.com_num = tweet.comment_set.all().count()
        new_tweet.isf = True
        tweet_list.append(new_tweet)
    tweet_list.sort(key=lambda x:x.tweet.tweet_time, reverse = True)
    tweet_num = Tweet.objects.filter(user = user_).count()
    no_num = Notition.objects.filter(to_user = user_).filter(status = "1").count()
    friend_num = len(friends)
    '''##'''
    page_num = len(tweet_list)/pageItemNum
    if request.GET.has_key('page'):
       current_page = int(request.GET['page'])
    '''##'''
    c = Context({"tweet_list": tweet_list[current_page*pageItemNum:(1 + current_page)*pageItemNum],\
    "friends" :friends, "current_user" : user_, \
    #
    'current_page': current_page,\
    'page_num': page_num,\
    #
    "friend_num":friend_num, "tweet_num":tweet_num,\
    "invitation_num":FriendshipInvitation.objects.filter\
    (to_user = request.user).filter( status = "1").count(),
    "notition_num": no_num})
    return render_to_response("home3.html", c)