Exemple #1
0
    def generate():
        #subs = PostsSubscription.objects.order_by('-date')
        logger.info("Copying subscriptions")
        elapsed, progress = timer_func()
        stream = zip(count(1), posts)
        stream = islice(stream, limit)

        for index, post in stream:
            progress(index, msg="subscriptions")
            #user = users.get(str(sub.user_id))
            #post = posts.get(str(sub.post_id))

            # Skip incomplete data or subs already made
            if not (user and post):
                continue

            # Skip users that have a digest
            if user.profile.digest_prefs != Profile.NO_DIGEST:
                continue

            sub = Subscription(uid=sub.id,
                               type=sub.type,
                               user=user,
                               post=post,
                               date=sub.date)

            yield sub
def bulk_create_subs(rows, column, pdict, udict):
    for row in rows:
        row = {col: val for col, val in zip(column, row)}
        user = udict.get(row['user_id'])
        post = pdict.get(str(row['post_id']))

        # Skip incomplete data.
        if not (user and post):
            continue

        sub = Subscription(uid=row['id'], type=row['type'], user=user, post=post, date=row['date'])

        yield sub
    def generate():
        subs = PostsSubscription.objects.order_by('-date')
        logger.info("Copying subscriptions")
        elapsed, progress = timer_func()
        stream = zip(count(1), subs)
        stream = islice(stream, limit)

        for index, sub in stream:
            progress(index, msg="subscriptions")
            user = users.get(str(sub.user_id))
            post = posts.get(str(sub.post_id))

            # Skip incomplete data or subs already made
            if not (user and post):
                continue

            sub = Subscription(type=sub.type, user=user, post=post, date=sub.date)

            yield sub
def follow_label(context, post):
    user = context["request"].user

    not_following = "not following"

    label_map = {
        Subscription.LOCAL_MESSAGE: "following with messages",
        Subscription.EMAIL_MESSAGE: "following via email",
        Subscription.NO_MESSAGES: not_following,
    }

    if user.is_anonymous:
        return not_following

    # Get the current subscription
    sub = Subscription.objects.filter(post=post.root, user=user).first()
    sub = sub or Subscription(post=post, user=user, type=Subscription.NO_MESSAGES)

    label = label_map.get(sub.type, not_following)

    return label
Exemple #5
0
    def generate():
        users = {user.profile.uid: user for user in User.objects.all()}
        posts = {post.uid: post for post in Post.objects.all()}
        subs = PostsSubscription.objects.all()

        logger.info("Copying subscriptions")
        elapsed, progress = timer_func()
        stream = zip(count(1), subs)
        stream = islice(stream, LIMIT)

        for index, sub in stream:
            progress(index, msg="subscriptions")
            user = users.get(str(sub.user_id))
            post = posts.get(str(sub.post_id))

            # Skip incomplete data
            if not (user and post):
                continue
            sub = Subscription(uid=sub.id, type=sub.type, user=user, post=post, date=sub.date)

            yield sub