Пример #1
0
def new_achievement(sender, instance, **kwargs):
    achievements_obtained = len(AchievementMembership.objects.filter(user=instance.user))

    if achievements_obtained == 10:
        # Hazte con todos!
        # you obtain 10 achievements
        achievement_check_ws(instance.user, "hazte_con_todos")
Пример #2
0
def new_friendship(sender, instance, **kwargs):
    followed_user_total_followers = len(UserFriendship.objects.filter(friend=instance.friend))
    first_user_follow = len(UserFriendship.objects.filter(follower=instance.follower, follow=True))

    if first_user_follow == 1:
        # Get over here
        # You follow a user for the first time
        achievement_check_ws(instance.follower, "get_over_here")

    if followed_user_total_followers == 1:
        # Hello, Hello, Follow me, Ok
        # A user follows you for the first time
        achievement_check_ws(instance.friend, "hello_hello_follow_me_ok")

    elif followed_user_total_followers == 25:
        # ¡Conquistar el mundo!
        # 25 users follow you
        achievement_check_ws(instance.friend, "conquistar_el_mundo")

    elif followed_user_total_followers == 50:
        # Capitan Olimar
        # 50 users follow you
        achievement_check_ws(instance.friend, "capitan_olimar")

    elif followed_user_total_followers == 100:
        # WOLOLO
        # A hundred users follow you
        achievement_check_ws(instance.friend, "wololo")
Пример #3
0
def update_user(sender, instance, **kwargs):
    # Player Select
    # You change your avatar for first time
    user = User.objects.filter(id=instance.id).first()
    if user:
        if user.avatar == 'avatar-default.svg':
            achievement_check_ws(user, "player_select")
Пример #4
0
def new_tag_follow(sender, instance, **kwargs):
    first_tag_follow = len(TagFollow.objects.filter(follower=instance.follower))

    if first_tag_follow == 1:
        # vayas_donde_vayas_siempre_te_encontrare
        # You follow a tag for the first time
        achievement_check_ws(instance.follower, "vayas_donde_vayas_siempre_te_encontrare")
Пример #5
0
    def get(self, request):
        try:
            achievement_check_ws(request.user, "manda_cuando_hayas_aprendido_a_obedecer")

            return Response({"status": "Success"}, status=status.HTTP_201_CREATED)

        except Exception as e:
            logger.error(e)
            return Response({"status": "Warning"}, status=status.HTTP_304_NOT_MODIFIED)
Пример #6
0
def new_user(sender, instance, created, **kwargs):
    if created:
        # Create default user preferences
        Preferences.objects.create(user=instance)

        # It's dangerous to go alone, take this!
        # Register on page
        achievement_check_ws(instance, "its_dangerous_to_go_alone_take_this")

        from API.user.models.user import Title
        from API.user.models.user import TitleMembership
        noob_level_1_title, created = TitleMembership.objects.get_or_create(
            user=instance,
            title=Title.objects.get(slug="noob_level_1"),
            active=True,
        )

        from API.user.models.user import Border
        from API.user.models.user import BorderMembership
        noob_level_1_border, created = BorderMembership.objects.get_or_create(
            user=instance,
            border=Border.objects.get(slug="noob_level_1"),
            active=True,
        )

        aniversary = datetime.date(2018, 11, 30)
        week_delta = datetime.timedelta(days=8)

        if aniversary - week_delta <= datetime.date.today() <= aniversary + week_delta:
            # Pong
            # Register on page during the initial week or aniversary
            achievement_check_ws(instance, "pong")

            primera_oleada, created = BorderMembership.objects.get_or_create(
                user=instance,
                border=Border.objects.get(slug="primera_oleada"),
                active=True,
            )
Пример #7
0
def new_comment(sender, instance, **kwargs):
    # Check if it is the first comment I write
    sender_comment_total = len(
        Comment.objects.filter(user_id=instance.user.id))
    if sender_comment_total == 1 and instance.parent:
        user_to_send = instance.user

        # Objection!
        achievement_check_ws(user_to_send, "objection")

    # Check if its the answer to other comment
    if instance.parent:
        receiver_comment_total = len(
            Comment.objects.filter(user_id=instance.parent.user.id))
        user_to_send = instance.parent.user

        if receiver_comment_total == 1:
            achievement_check_ws(user_to_send, "its_on_like_donkey_kong")

        notification = Notification.objects.create(
            notification_type="comment",
            owner=user_to_send,
            new_post=instance,
            new_publication=instance.publication,
            notification_message="{publication_title}".format(
                publication_title=instance.publication.title))

        channel_layer = get_channel_layer()
        serialized_notification = NotificationSerializer(notification).data
        async_to_sync(channel_layer.group_send)(
            slugify(user_to_send.username),
            {
                "type": "message",
                "data": serialized_notification
            },
        )
Пример #8
0
def new_post_vote(sender, instance, **kwargs):
    user_to_send = instance.post.user

    # ################################################### #
    # ### CHECK NUMBER OF LIKES IN INDIVIDUAL COMMENT ### #
    # ################################################### #
    if instance.post.total_votes == 1:
        # ACHIEVEMENT: 1 UP
        achievement_check_ws(user_to_send, "1up")

    elif instance.post.total_votes == 25:
        # ACHIEVEMENT: ¡ES SUPER EFECTIVO!
        achievement_check_ws(user_to_send, "es_super_efectivo")

    elif instance.post.total_votes == 50:
        # ACHIEVEMENT: BIG BOSS
        achievement_check_ws(user_to_send, "big_boss")

    elif instance.post.total_votes == 100:
        # ACHIEVEMENT: MASTER CHIEF
        achievement_check_ws(user_to_send, "master_chief")

    elif instance.post.total_votes == 250:
        # ACHIEVEMENT: JACKPOT!
        achievement_check_ws(user_to_send, "jackpot")

    elif instance.post.total_votes == 250:
        # ACHIEVEMENT: HAIL TO THE KING, BABY!
        achievement_check_ws(user_to_send, "hail_to_the_king_baby")

    # ###################################################### #
    # ### CHECK NUMBER OF COMMENTS WITH AT LEST ONE LIKE ### #
    # ###################################################### #
    total_voted_posts = len(Comment.objects.filter(total_votes__gte=0))
    if total_voted_posts == 25:
        # GO GO GO!
        achievement_check_ws(user_to_send, "go_go_go")

    elif total_voted_posts == 50:
        # Nada es verdad, toudo esta permitido
        achievement_check_ws(user_to_send, "nada_es_verdad_todo_esta_permitido")

    elif total_voted_posts == 100:
        # Rosebud
        achievement_check_ws(user_to_send, "rosebud")

    elif total_voted_posts == 250:
        # Ya no hay noticias, solo propaganda
        achievement_check_ws(user_to_send, "ya_no_hay_noticias_solo_propaganda")

    elif total_voted_posts == 250:
        # Hey, listen!
        achievement_check_ws(user_to_send, "hey_listen")