示例#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)
示例#2
0
def home_hot(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()
            new_notition = Notition(
                f_comm = new_comment,
                t_comm = new_comment,
                to_tweet = to_tweet,
                to_user = to_tweet.user,
                noti_type = "1",
                status = "1"
            )
            new_notition.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"])
            isf = Friendship.objects.are_friends(s_user, request.user)
            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 = isf
                tweet_list.append(new_tweet)
            tweet_list.sort(key=lambda x:(x.com_num, 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()
            '''##'''
            page_num = tweet_num/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("home1.html", c)
        
    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_list = []
    for tweet in Tweet.objects.all():
        new_tweet = Tweets(tweet)
        new_tweet.comments = list(tweet.comment_set.all())
        new_tweet.com_num = tweet.comment_set.all().count()
        new_tweet.isf = Friendship.objects.are_friends(tweet.user, request.user)
        tweet_list.append(new_tweet)
    tweet_list.sort(key=lambda x:(x.com_num, 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()
    '''##'''
    page_num = tweet_num/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("home1.html", c)