Example #1
0
 def appendPollVotesAndComments(self, user_feed, poll, user_related=False, watching=False, start_index=None, end_index=None):
     """
     This method basically makes sure we dont add certain things to the feed more than once
     like a VoteItem or a CommentItem, so we test the feed to see if it already has that item, if it does not
     then we are free to add it.
     This method only acts on a set of polls
     """
     votes = PollVote.objects.filter(poll=poll).order_by('-date_created')   #@UndefinedVariable
     for v in votes:
         timestamp = time.mktime(v.date_created.timetuple())
         vi = VoteItem(vote=v, timestamp=timestamp, poll=v.poll, date=v.date_created)                       
         try:
             vi = user_feed[user_feed.index(vi)]                                        
         except ValueError:                                
             user_feed.append(vi)
         if watching:
             vi.watching_related = watching
         if user_related:                
             vi.user_related = user_related                
 
     # get all comments for your polls
     comments = ThreadedComment.objects.filter(object_id=poll.id).order_by('-date_modified')
     for c in comments:
         timestamp = time.mktime(c.date_modified.timetuple())
         ci = CommentItem(comment=c, timestamp=timestamp, poll=c.content_object, date=c.date_modified)                            
         try:
             ci = user_feed[user_feed.index(ci)]
         except ValueError:
             user_feed.append(ci)
         if watching:
             ci.watching_related = watching
         if user_related:
             ci.user_related = user_related            
             
     return user_feed
Example #2
0
    def appendPollVotesAndComments(self,
                                   user_feed,
                                   poll,
                                   user_related=False,
                                   watching=False,
                                   start_index=None,
                                   end_index=None):
        """
        This method basically makes sure we dont add certain things to the feed more than once
        like a VoteItem or a CommentItem, so we test the feed to see if it already has that item, if it does not
        then we are free to add it.
        This method only acts on a set of polls
        """
        votes = PollVote.objects.filter(poll=poll).order_by(
            '-date_created')  #@UndefinedVariable
        for v in votes:
            timestamp = time.mktime(v.date_created.timetuple())
            vi = VoteItem(vote=v,
                          timestamp=timestamp,
                          poll=v.poll,
                          date=v.date_created)
            try:
                vi = user_feed[user_feed.index(vi)]
            except ValueError:
                user_feed.append(vi)
            if watching:
                vi.watching_related = watching
            if user_related:
                vi.user_related = user_related

        # get all comments for your polls
        comments = ThreadedComment.objects.filter(
            object_id=poll.id).order_by('-date_modified')
        for c in comments:
            timestamp = time.mktime(c.date_modified.timetuple())
            ci = CommentItem(comment=c,
                             timestamp=timestamp,
                             poll=c.content_object,
                             date=c.date_modified)
            try:
                ci = user_feed[user_feed.index(ci)]
            except ValueError:
                user_feed.append(ci)
            if watching:
                ci.watching_related = watching
            if user_related:
                ci.user_related = user_related

        return user_feed
Example #3
0
    def getUserFeed(self, user, owner=False, phase=0, request_user=None):
        """
        Gets the activity feed for a user
        This method is the hoss method of all methods in methodtown
        """

        us = UserService(user=user)
        userdata = us.getUserData()
        userdata_friends = userdata.friends.all()
        if not owner:
            request_user_friends = UserService(user=request_user).getFriends()
            friend_ids = [friend.id for friend in request_user_friends]
            userdata_friends = userdata_friends.filter(id__in=friend_ids)

        user_feed = []
        # create the motherfuckin window bitches!!!!!!
        start_index = phase * consts.POLL_ACTIVITY_WINDOW
        end_index = (phase + 1) * consts.POLL_ACTIVITY_WINDOW
        self.log.debug("start index: %d -- end index: %d" %
                       (start_index, end_index))
        self.log.debug("Phase: %d" % phase)
        if owner:
            # only show friends stuff on owner feed
            for f in userdata_friends:
                # get polls friends created
                friend_polls = Poll.objects.filter(
                    user=f,
                    active=True).order_by('-date_created')  #@UndefinedVariable
                for fp in friend_polls:
                    timestamp = time.mktime(fp.date_created.timetuple())
                    ci = CreatedItem(timestamp=timestamp,
                                     poll=fp,
                                     date=fp.date_created)
                    ci.friend_related = True
                    user_feed.append(ci)

                # get friends votes
                friend_votes = PollVote.objects.filter(user=f).order_by(
                    '-date_created')  #@UndefinedVariable
                for fv in friend_votes:
                    timestamp = time.mktime(fv.date_created.timetuple())
                    vi = VoteItem(vote=fv,
                                  timestamp=timestamp,
                                  poll=fv.poll,
                                  date=fv.date_created)
                    vi.friend_related = True
                    vi.friend_voted = True
                    user_feed.append(vi)

                # get friends comments
                friend_comments = ThreadedComment.objects.filter(
                    user=f).order_by('-date_modified')
                for fc in friend_comments:
                    timestamp = time.mktime(fc.date_modified.timetuple())
                    ci = CommentItem(comment=fc,
                                     timestamp=timestamp,
                                     poll=fc.content_object,
                                     date=fc.date_modified)
                    ci.friend_related = True
                    ci.friend_commented = True
                    user_feed.append(ci)

        # get polls created by user
        user_polls = Poll.objects.filter(user=user, active=True).order_by(
            '-date_created')  #@UndefinedVariable
        for poll in user_polls:
            self.appendPollVotesAndComments(user_feed=user_feed,
                                            poll=poll,
                                            user_related=True,
                                            start_index=start_index,
                                            end_index=end_index)

            # add polls user created
            timestamp = time.mktime(poll.date_created.timetuple())
            ci = CreatedItem(timestamp=timestamp,
                             poll=poll,
                             date=poll.date_created)
            ci.user_related = True
            user_feed.append(ci)

        # get user's watched polls
        watched_polls = userdata.polls_watched.order_by('-poll__date_modified')
        for wp in watched_polls:
            self.appendPollVotesAndComments(user_feed=user_feed,
                                            poll=wp.poll,
                                            watching=True,
                                            start_index=start_index,
                                            end_index=end_index)

        # get users votes
        user_votes = PollVote.objects.filter(user=user).order_by(
            '-date_created')  #@UndefinedVariable
        for uv in user_votes:
            timestamp = time.mktime(uv.date_created.timetuple())
            vi = VoteItem(vote=uv,
                          timestamp=timestamp,
                          poll=uv.poll,
                          date=uv.date_created)
            try:
                vi = user_feed[user_feed.index(vi)]
            except ValueError:
                user_feed.append(vi)
            vi.user_voted = True

        # get user comments
        user_comments = ThreadedComment.objects.filter(
            user=user).order_by('-date_modified')
        for uc in user_comments:
            timestamp = time.mktime(uc.date_modified.timetuple())
            ci = CommentItem(comment=uc,
                             timestamp=timestamp,
                             poll=uc.content_object,
                             date=uc.date_modified)
            try:
                ci = user_feed[user_feed.index(ci)]
            except ValueError:
                user_feed.append(ci)
            ci.user_commented = True

        # sort that shit out
        remain = len(user_feed) > end_index
        user_feed.sort()
        user_feed.reverse()
        # TODO: FOR THE LOVE OF GOD CACHE THE F*****G USER_FEED RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!
        user_feed = user_feed[start_index:end_index]
        return user_feed, remain
Example #4
0
    def getUserFeed(self, user, owner=False, phase=0, request_user=None):
        """
        Gets the activity feed for a user
        This method is the hoss method of all methods in methodtown
        """
        
        us = UserService(user=user)
        userdata = us.getUserData()
        userdata_friends = userdata.friends.all()
        if not owner:
            request_user_friends = UserService(user=request_user).getFriends()
            friend_ids = [friend.id for friend in request_user_friends]
            userdata_friends = userdata_friends.filter(id__in=friend_ids) 
                        
        user_feed = []
        # create the motherfuckin window bitches!!!!!!
        start_index = phase * consts.POLL_ACTIVITY_WINDOW
        end_index = (phase+1) *  consts.POLL_ACTIVITY_WINDOW
        self.log.debug("start index: %d -- end index: %d" % (start_index, end_index))
        self.log.debug("Phase: %d" % phase)
        if owner:
            # only show friends stuff on owner feed
            for f in userdata_friends:
                # get polls friends created                
                friend_polls = Poll.objects.filter(user=f, active=True).order_by('-date_created')   #@UndefinedVariable
                for fp in friend_polls:
                    timestamp = time.mktime(fp.date_created.timetuple())
                    ci = CreatedItem(timestamp=timestamp, poll=fp, date=fp.date_created)
                    ci.friend_related = True
                    user_feed.append(ci)
                    
                # get friends votes
                friend_votes = PollVote.objects.filter(user=f).order_by('-date_created')   #@UndefinedVariable
                for fv in friend_votes:
                    timestamp = time.mktime(fv.date_created.timetuple())
                    vi = VoteItem(vote=fv, timestamp=timestamp, poll=fv.poll, date=fv.date_created)
                    vi.friend_related = True
                    vi.friend_voted = True
                    user_feed.append(vi)
                
                # get friends comments
                friend_comments = ThreadedComment.objects.filter(user=f).order_by('-date_modified')
                for fc in friend_comments:
                    timestamp = time.mktime(fc.date_modified.timetuple())
                    ci = CommentItem(comment=fc, timestamp=timestamp, poll=fc.content_object, date=fc.date_modified)
                    ci.friend_related = True
                    ci.friend_commented = True
                    user_feed.append(ci)

        # get polls created by user
        user_polls = Poll.objects.filter(user=user, active=True).order_by('-date_created')   #@UndefinedVariable
        for poll in user_polls:
            self.appendPollVotesAndComments(user_feed=user_feed, poll=poll, user_related=True, start_index=start_index, end_index=end_index)
            
            # add polls user created
            timestamp = time.mktime(poll.date_created.timetuple())
            ci = CreatedItem(timestamp=timestamp, poll=poll, date=poll.date_created)
            ci.user_related = True
            user_feed.append(ci)
        
        # get user's watched polls
        watched_polls = userdata.polls_watched.order_by('-poll__date_modified')                
        for wp in watched_polls:
            self.appendPollVotesAndComments(user_feed=user_feed, poll=wp.poll, watching=True, start_index=start_index, end_index=end_index)
        
        # get users votes
        user_votes = PollVote.objects.filter(user=user).order_by('-date_created')   #@UndefinedVariable
        for uv in user_votes:
            timestamp = time.mktime(uv.date_created.timetuple())
            vi = VoteItem(vote=uv, timestamp=timestamp, poll=uv.poll, date=uv.date_created)
            try:
                vi = user_feed[user_feed.index(vi)]                                        
            except ValueError:                                
                user_feed.append(vi)
            vi.user_voted = True
        
        # get user comments
        user_comments = ThreadedComment.objects.filter(user=user).order_by('-date_modified')
        for uc in user_comments:
            timestamp = time.mktime(uc.date_modified.timetuple())
            ci = CommentItem(comment=uc, timestamp=timestamp, poll=uc.content_object, date=uc.date_modified)
            try:
                ci = user_feed[user_feed.index(ci)]                                        
            except ValueError:                                
                user_feed.append(ci)
            ci.user_commented = True
        
        # sort that shit out
        remain = len(user_feed) > end_index
        user_feed.sort()
        user_feed.reverse()
        # TODO: FOR THE LOVE OF GOD CACHE THE F*****G USER_FEED RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!
        user_feed = user_feed[start_index:end_index]
        return user_feed, remain