コード例 #1
0
ファイル: util.py プロジェクト: krdeepak/djmysite
def refresh_feed():
    questions = Question.objects.filter(is_new=1)
    users = User.objects.all()
    for q in questions:
        if not q.group or q.group.membership == 2:
            for u in users:
                if exists_in_feed(q, u):
                    continue
                # score = poll_score(q, u)
                score = 10
                feed = Feed()
                feed.user = u
                feed.question = q
                feed.score = score
                feed.save()
        elif q.group.id == 1:
            for u in q.user.userprofile.friends:
                if exists_in_feed(q, u):
                    continue
                # score = poll_score(q, u)
                score = 50
                feed = Feed()
                feed.user = u
                feed.question = q
                feed.score = score
                feed.save()

            # Allow the question creator to vote also
            Feed(user=q.user, question=q, score=50).save()

        else:
            group = Group.objects.get(pk=q.group.id)
            for u in [x.user for x in group.member_set.filter(pending=0)]: # private group
                if exists_in_feed(q, u):
                    continue
                score = 30
                feed = Feed()
                feed.user = u
                feed.question = q
                feed.score = score
                feed.save()
            for u in [x.user for x in group.openmember_set.all()]: # public group
                if exists_in_feed(q, u):
                    continue
                score = 20
                feed = Feed()
                feed.user = u
                feed.question = q
                feed.score = score
                feed.save()

        q.is_new = 0
        q.save()
コード例 #2
0
ファイル: util.py プロジェクト: krdeepak/djmysite
def create_feed_new_user(user):
    questions = Question.objects.all()[:1000]
    for q in questions:
        if not q.group:
            score = 10
            feed = Feed()
            feed.user = user
            feed.question = q
            feed.score = score
            feed.save()
        elif q.group.id == 1:
            if q.user.id in [x.id for x in user.userprofile.friends]:
                # score = poll_score(q, u)
                score = 50
                feed = Feed()
                feed.user = user
                feed.question = q
                feed.score = score
                feed.save()
        else:
            # new user not added to any group just after joining
            pass