def create_thank(sender, instance, created, **kwargs): """ Create a notification for the writer of the review. Create a karma action for the agree. Increment the giver's thanks by one and karma by one. Increment the receiver's thanks by one and karma by two. """ if created: signalAPI.queue_notification(sender_id=instance.giver_id, recipient_id=instance.review.user_id, model_name="thank", obj_id=instance.pk) signalAPI.add_karma_action(recipient_id=instance.review.user_id, giver_id=instance.giver_id, karma=1) signalAPI.update_statistics(model_name="userstatistics", obj_id=instance.giver_id, thanks_out=1) signalAPI.update_statistics(model_name="userstatistics", obj_id=instance.review.user_id, thanks_in=1, karma=1) signalAPI.update_statistics(model_name="review", obj_id=instance.review_id, thanks=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)
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})
def follow_notification(sender, instance, created, **kwargs): if created: signalAPI.queue_notification( sender_id=instance.source_id, recipient_id=instance.destination_id, model_name="backward", obj_id=instance.pk )
def create_thank(sender, instance, created, **kwargs): """ Create a notification for the writer of the review. Create a karma action for the agree. Increment the giver's thanks by one and karma by one. Increment the receiver's thanks by one and karma by two. """ if created: signalAPI.queue_notification( sender_id=instance.giver_id, recipient_id=instance.review.user_id, model_name="thank", obj_id=instance.pk ) signalAPI.add_karma_action( recipient_id=instance.review.user_id, giver_id=instance.giver_id, karma=1 ) signalAPI.update_statistics( model_name="userstatistics", obj_id=instance.giver_id, thanks_out=1 ) signalAPI.update_statistics( model_name="userstatistics", obj_id=instance.review.user_id, thanks_in=1, karma=1 ) signalAPI.update_statistics( model_name="review", obj_id=instance.review_id, thanks=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 )
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 } )
def follow_notification(sender, instance, created, **kwargs): if created: signalAPI.queue_notification(sender_id=instance.source_id, recipient_id=instance.destination_id, model_name="backward", obj_id=instance.pk)