Esempio n. 1
0
def delete_review(sender, instance, **kwargs):
    """
    Deletes all related activities, agrees, and thanks.
    Undo the updates when the review was created.
    """
    signalAPI.filter_then_delete(
        model_name="activity",
        content_type=signalAPI.get_content_type("review"),
        object_id=instance.pk)
    signalAPI.filter_then_delete(model_name="agree", review=instance.pk)
    signalAPI.filter_then_delete(model_name="thank", review=instance.pk)
    signalAPI.update_statistics(model_name="userstatistics",
                                obj_id=instance.user_id,
                                reviews=-1,
                                karma=-5)
    rating = utils.get_rating_field(instance.rating)
    signalAPI.update_statistics(model_name="item",
                                obj_id=instance.item_id,
                                **{
                                    rating: -1,
                                    'reviews': -1
                                })
    signalAPI.update_statistics(model_name="popularity",
                                obj_id=instance.item_id,
                                **utils.decrement_popularities(
                                    instance.created_at, instance.rating))
    agrees = signalAPI.filter_then_order_by(model_name="agree",
                                            order_criteria="-created_at",
                                            giver=instance.user_id,
                                            review__item=instance.item_id)
    if agrees:
        rating = utils.get_rating_field(agrees[0].review.rating)
        signalAPI.update_statistics(model_name="item",
                                    obj_id=instance.item_id,
                                    **{rating: 1})
Esempio n. 2
0
def delete_agree(sender, instance, **kwargs):
    """
    Undo the updates when the agree was created.
    """
    try:
        instance.review
    except ObjectDoesNotExist:
        return False
    signalAPI.remove_activity(sender_id=instance.giver_id,
                              verb="re-raved",
                              model_name="review",
                              obj_id=instance.review_id)
    signalAPI.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)))
    signalAPI.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)))
    signalAPI.update_statistics(model_name="userstatistics",
                                obj_id=instance.giver_id,
                                agrees_out=-1,
                                karma=-1)
    signalAPI.update_statistics(model_name="userstatistics",
                                obj_id=instance.review.user_id,
                                agrees_in=-1,
                                karma=-2)
    signalAPI.update_statistics(model_name="review",
                                obj_id=instance.review_id,
                                agrees=-1)
    signalAPI.update_statistics(model_name="popularity",
                                obj_id=instance.review.item_id,
                                **utils.decrement_popularities(
                                    instance.created_at,
                                    instance.review.rating))
    reviews = signalAPI.filter_then_count(model_name="review",
                                          user=instance.giver_id,
                                          item=instance.review.item_id)
    if reviews == 0:
        remaining = signalAPI.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)
            signalAPI.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)
                signalAPI.update_statistics(model_name="item",
                                            obj_id=instance.review.item_id,
                                            **{new_rating: 1})
Esempio n. 3
0
def create_agree(sender, instance, created, **kwargs):
    """
    Creates a notification for the writer of the review.
    Create two karma actions for the agree.
    Increment the giver's agrees by one and karma by one.
    Increment the receiver's agrees by one and karma by two.
    Increment the item's rating count by one.
    """
    if created:
        signalAPI.queue_activity(sender_id=instance.giver_id,
                                 verb="re-raved",
                                 model_name="review",
                                 obj_id=instance.review_id)
        signalAPI.queue_notification(sender_id=instance.giver_id,
                                     recipient_id=instance.review.user_id,
                                     model_name="agree",
                                     obj_id=instance.pk)
        signalAPI.add_karma_action(recipient_id=instance.review.user_id,
                                   giver_id=instance.giver_id,
                                   karma=2)
        signalAPI.add_karma_action(recipient_id=instance.giver_id,
                                   giver_id=instance.giver_id,
                                   karma=1)
        signalAPI.update_statistics(model_name="userstatistics",
                                    obj_id=instance.giver_id,
                                    agrees_out=1,
                                    karma=1)
        signalAPI.update_statistics(model_name="userstatistics",
                                    obj_id=instance.review.user_id,
                                    agrees_in=1,
                                    karma=2)
        signalAPI.update_statistics(model_name="review",
                                    obj_id=instance.review_id,
                                    agrees=1)
        signalAPI.update_statistics(model_name="popularity",
                                    obj_id=instance.review.item_id,
                                    today=instance.review.rating,
                                    week=instance.review.rating,
                                    month=instance.review.rating,
                                    alltime=instance.review.rating)
        reviews = signalAPI.filter_then_count(model_name="review",
                                              user=instance.giver_id,
                                              item=instance.review.item_id)
        if reviews == 0:
            rating = utils.get_rating_field(instance.review.rating)
            signalAPI.update_statistics(model_name="item",
                                        obj_id=instance.review.item_id,
                                        **{rating: 1})
            old_agrees = signalAPI.filter_excluding_me_then_order_by(
                model_name="agree",
                obj_id=instance.pk,
                order_criteria="-created_at",
                giver=instance.giver_id,
                review__item=instance.review.item_id)
            if old_agrees:
                rating = utils.get_rating_field(old_agrees[0].review.rating)
                signalAPI.update_statistics(model_name="item",
                                            obj_id=instance.review.item_id,
                                            **{rating: -1})
Esempio n. 4
0
def create_review(sender, instance, created, **kwargs):
    """
    Queue an activity for the review.
    Create a karma action for the review.
    Increment the user's reviews by one and karma by five.
    Update the item's ratings by the review's rating.
    Update the item's popularity by the review's rating.
    """
    if created:
        api.queue_activity(
            sender_id=instance.user_id, 
            verb="raved about",
            model_name="review",
            obj_id=instance.pk
        )
        api.add_karma_action(
            recipient_id=instance.user_id,
            giver_id=instance.user_id,
            karma=5
        )
        api.update_statistics(
            model_name="userstatistics",
            obj_id=instance.user_id,
            reviews=1,
            karma=5
        )
        rating = utils.get_rating_field(instance.rating)
        api.update_statistics(
            model_name="item",
            obj_id=instance.item_id,
            **{ rating: 1, 'reviews': 1 }
        )
        api.update_statistics(
            model_name="popularity",
            obj_id=instance.item_id,
            today=instance.rating,
            week=instance.rating,
            month=instance.rating,
            alltime=instance.rating
        )
        agrees = api.filter_then_order_by(
            model_name="agree",
            order_criteria="-created_at",
            giver=instance.user_id,
            review__item=instance.item_id
        )
        if agrees:
            rating = utils.get_rating_field(agrees[0].review.rating)
            api.update_statistics(
                model_name="item",
                obj_id=instance.item_id,
                **{ rating: -1}
            )
Esempio n. 5
0
def delete_review(sender, instance, **kwargs):
    """
    Deletes all related activities, agrees, and thanks.
    Undo the updates when the review was created.
    """
    api.filter_then_delete(
        model_name="activity",
        content_type=api.get_content_type("review"),
        object_id=instance.pk
    )
    api.filter_then_delete(model_name="agree", review=instance.pk)
    api.filter_then_delete(model_name="thank", review=instance.pk)
    api.update_statistics(
        model_name="userstatistics",
        obj_id=instance.user_id,
        reviews=-1,
        karma=-5
    )
    rating = utils.get_rating_field(instance.rating)
    api.update_statistics(
        model_name="item",
        obj_id=instance.item_id,
        **{ rating: -1, 'reviews': -1 }
    )
    api.update_statistics(
        model_name="popularity",
        obj_id=instance.item_id,
        **utils.decrement_popularities(instance.created_at,
            instance.rating)
    )
    agrees = api.filter_then_order_by(
        model_name="agree",
        order_criteria="-created_at",
        giver=instance.user_id,
        review__item=instance.item_id
    )
    if agrees:
        rating = utils.get_rating_field(agrees[0].review.rating)
        api.update_statistics(
            model_name="item",
            obj_id=instance.item_id,
            **{ rating: 1 }
        )
Esempio n. 6
0
def create_review(sender, instance, created, **kwargs):
    """
    Queue an activity for the review.
    Create a karma action for the review.
    Increment the user's reviews by one and karma by five.
    Update the item's ratings by the review's rating.
    Update the item's popularity by the review's rating.
    """
    if created:
        signalAPI.queue_activity(sender_id=instance.user_id,
                                 verb="raved about",
                                 model_name="review",
                                 obj_id=instance.pk)
        signalAPI.add_karma_action(recipient_id=instance.user_id,
                                   giver_id=instance.user_id,
                                   karma=5)
        signalAPI.update_statistics(model_name="userstatistics",
                                    obj_id=instance.user_id,
                                    reviews=1,
                                    karma=5)
        rating = utils.get_rating_field(instance.rating)
        signalAPI.update_statistics(model_name="item",
                                    obj_id=instance.item_id,
                                    **{
                                        rating: 1,
                                        'reviews': 1
                                    })
        signalAPI.update_statistics(model_name="popularity",
                                    obj_id=instance.item_id,
                                    today=instance.rating,
                                    week=instance.rating,
                                    month=instance.rating,
                                    alltime=instance.rating)
        agrees = signalAPI.filter_then_order_by(model_name="agree",
                                                order_criteria="-created_at",
                                                giver=instance.user_id,
                                                review__item=instance.item_id)
        if agrees:
            rating = utils.get_rating_field(agrees[0].review.rating)
            signalAPI.update_statistics(model_name="item",
                                        obj_id=instance.item_id,
                                        **{rating: -1})
Esempio n. 7
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 }
                )
Esempio n. 8
0
def create_agree(sender, instance, created, **kwargs):
    """
    Creates a notification for the writer of the review.
    Create two karma actions for the agree.
    Increment the giver's agrees by one and karma by one.
    Increment the receiver's agrees by one and karma by two.
    Increment the item's rating count by one.
    """
    if created:
        api.queue_activity(
            sender_id=instance.giver_id,
            verb="re-raved",
            model_name="review",
            obj_id=instance.review_id
        )
        api.queue_notification(
            sender_id=instance.giver_id,
            recipient_id=instance.review.user_id,
            model_name="agree",
            obj_id=instance.pk
        )
        api.add_karma_action(
            recipient_id=instance.review.user_id,
            giver_id=instance.giver_id,
            karma=2
        )
        api.add_karma_action(
            recipient_id=instance.giver_id,
            giver_id=instance.giver_id,
            karma=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,
            today=instance.review.rating,
            week=instance.review.rating,
            month=instance.review.rating,
            alltime=instance.review.rating
        )
        reviews = api.filter_then_count(
            model_name="review",
            user=instance.giver_id,
            item=instance.review.item_id
        )
        if reviews == 0:
            rating = utils.get_rating_field(instance.review.rating)
            api.update_statistics(
                model_name="item",
                obj_id=instance.review.item_id,
                **{ rating: 1}
            )
            old_agrees = api.filter_excluding_me_then_order_by(
                model_name="agree",
                obj_id=instance.pk,
                order_criteria="-created_at",
                giver=instance.giver_id,
                review__item=instance.review.item_id
            )
            if old_agrees:
                rating = utils.get_rating_field(
                                old_agrees[0].review.rating)
                api.update_statistics(
                    model_name="item",
                    obj_id=instance.review.item_id,
                    **{ rating: -1 }
                )