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