Beispiel #1
0
def delete_thank(sender, instance, **kwargs):
    """
    Undo the updates when the thank was created.
    """
    api.remove_notification(
        sender_id=instance.giver_id,
        recipient_id=instance.review.user_id,
        model_name="thank",
        obj_id=instance.pk
    )
    api.remove_karma_action(
        recipient_id=instance.review.user_id,
        giver_id=instance.giver_id,
        karma=1,
        time_range=(instance.created_at,
                    instance.created_at+dt.timedelta(hours=1))
    )
    api.update_statistics(
        model_name="userstatistics",
        obj_id=instance.giver_id,
        thanks_out=-1
    )
    api.update_statistics(
        model_name="userstatistics",
        obj_id=instance.review.user_id,
        thanks_in=-1,
        karma=-1
    )
    api.update_statistics(
        model_name="review",
        obj_id=instance.review_id,
        thanks=-1
    )
    api.update_statistics(
        model_name="popularity",
        obj_id=instance.review.item_id,
        **utils.decrement_popularities(instance.created_at,
            instance.review.rating)
    )
Beispiel #2
0
def delete_agree(sender, instance, **kwargs):
    """
    Undo the updates when the agree was created.
    """
    api.remove_activity(
        sender_id=instance.giver_id,
        verb="re-raved",
        model_name="review",
        obj_id=instance.review_id
    )
    api.remove_notification(
        sender_id=instance.giver_id,
        recipient_id=instance.review.user_id,
        model_name="agree",
        obj_id=instance.pk
    )
    api.remove_karma_action(
        recipient_id=instance.review.user_id,
        giver_id=instance.giver_id,
        karma=2,
        time_range=(instance.created_at,
                    instance.created_at+dt.timedelta(hours=1))
    )
    api.remove_karma_action(
        recipient_id=instance.giver_id,
        giver_id=instance.giver_id,
        karma=1,
        time_range=(instance.created_at,
                    instance.created_at+dt.timedelta(hours=1))
    )
    api.update_statistics(
       model_name="userstatistics",
       obj_id=instance.giver_id,
       agrees_out=-1,
       karma=-1
    )
    api.update_statistics(
        model_name="userstatistics",
        obj_id=instance.review.user_id,
        agrees_in=-1,
        karma=-2
    )
    api.update_statistics(
        model_name="review",
        obj_id=instance.review_id,
        agrees=-1
    )
    api.update_statistics(
        model_name="popularity",
        obj_id=instance.review.item_id,
        **utils.decrement_popularities(instance.created_at,
            instance.review.rating)
    )
    reviews = api.filter_then_count(
        model_name="review",
        user=instance.giver_id,
        item=instance.review.item_id
    )
    if reviews == 0:
        remaining = api.filter_then_order_by(
            model_name="agree",
            order_criteria="-created_at",
            giver=instance.giver_id,
            review__item=instance.review.item_id
        )
        if (not remaining or 
                    remaining[0].created_at < instance.created_at):
            old_rating = utils.get_rating_field(instance.review.rating)
            api.update_statistics(
                model_name="item",
                obj_id=instance.review.item_id,
                **{ old_rating: -1 }
            )
            if remaining:
                new_rating = utils.get_rating_field(
                    remaining[0].review.rating)
                api.update_statistics(
                    model_name="item",
                    obj_id=instance.review.item_id,
                    **{ new_rating: 1 }
                )