Exemple #1
0
def add_points_add_comment(user, point_event, timestamp=None,
                           comment_id=None, **kwargs):
    # Feature: limit to 15 points per day and per user for comments
    # Since we have ADD_COMMENT and REMOVE_COMMENT events that change the bonus points
    # acquired for comments this day we must make sure that if a user has exceeded
    # today's limit and he removes some comments, we must not remove points for the
    # comments that did not credited some points to the user. In fact, we must count
    # the number N of comments that did not credit points (including the previous days),
    # and the N first REMOVE_COMMENT events should not remove points. So we should remember
    # the ADD_COMMENT events that credited 0 points, that why we call the user.add_points
    # with 0 points credit.

    # Max 2 points per day, 1 point per comment
    credited_today = _nb_comments_points_credited_today(user, timestamp)
    if credited_today < 2:
        points_credited = _comment_points_by_date(timestamp)
    else:
        points_credited = 0

    # Log it for further debugging
    log.info(
        "Comment added by %s (credited_today=%s, points_credited=%s)" % (
            user, credited_today, points_credited))

    user.add_points(
        PointCategory.ADD_COMMENT,
        nb_points=points_credited,
        timestamp=timestamp,
        subject_id=comment_id
    )
Exemple #2
0
def add_points_add_comment(user,
                           point_event,
                           timestamp=None,
                           comment_id=None,
                           **kwargs):
    # Feature: limit to 15 points per day and per user for comments
    # Since we have ADD_COMMENT and REMOVE_COMMENT events that change the bonus points
    # acquired for comments this day we must make sure that if a user has exceeded
    # today's limit and he removes some comments, we must not remove points for the
    # comments that did not credited some points to the user. In fact, we must count
    # the number N of comments that did not credit points (including the previous days),
    # and the N first REMOVE_COMMENT events should not remove points. So we should remember
    # the ADD_COMMENT events that credited 0 points, that why we call the user.add_points
    # with 0 points credit.

    # Max 2 points per day, 1 point per comment
    credited_today = _nb_comments_points_credited_today(user, timestamp)
    if credited_today < 2:
        points_credited = _comment_points_by_date(timestamp)
    else:
        points_credited = 0

    # Log it for further debugging
    log.info("Comment added by %s (credited_today=%s, points_credited=%s)" %
             (user, credited_today, points_credited))

    user.add_points(PointCategory.ADD_COMMENT,
                    nb_points=points_credited,
                    timestamp=timestamp,
                    subject_id=comment_id)
Exemple #3
0
def add_points_remove_comment(user, point_event, timestamp=None,
                              comment_date=None, comment_id=None, **kwargs):
    from eureka.domain.models import PointData

    # TODO: implement the limit to 15 points per day per user
    # Feature: limit to 15 points per day and per user for comments
    #   (see comments for the ADD_COMMENT event handling)
    assert comment_date is not None

    # Try to find the added points when the comment was created
    pd = PointData.get_by(
        label=PointCategory.ADD_COMMENT,
        subject_id=comment_id
    )
    if pd is not None:
        points_removed = -pd.nb_points

    # Keep the old mechanism
    elif _remove_comment_event_should_remove_some_points(user, timestamp):
        points_removed = -_comment_points_by_date(comment_date)
    else:
        points_removed = 0

    reason = kwargs.get('reason', '')
    user.add_points(
        PointCategory.REMOVE_COMMENT,
        nb_points=points_removed,
        reason=reason,
        timestamp=timestamp,
        subject_id=comment_id
    )
Exemple #4
0
def add_points_remove_comment(user,
                              point_event,
                              timestamp=None,
                              comment_date=None,
                              comment_id=None,
                              **kwargs):
    from eureka.domain.models import PointData

    # TODO: implement the limit to 15 points per day per user
    # Feature: limit to 15 points per day and per user for comments
    #   (see comments for the ADD_COMMENT event handling)
    assert comment_date is not None

    # Try to find the added points when the comment was created
    pd = PointData.get_by(label=PointCategory.ADD_COMMENT,
                          subject_id=comment_id)
    if pd is not None:
        points_removed = -pd.nb_points

    # Keep the old mechanism
    elif _remove_comment_event_should_remove_some_points(user, timestamp):
        points_removed = -_comment_points_by_date(comment_date)
    else:
        points_removed = 0

    reason = kwargs.get('reason', '')
    user.add_points(PointCategory.REMOVE_COMMENT,
                    nb_points=points_removed,
                    reason=reason,
                    timestamp=timestamp,
                    subject_id=comment_id)