Beispiel #1
0
    def complete_award_to(self,
                          user_data,
                          target_context=None,
                          target_context_name=None):
        name_with_context = self.name_with_target_context(target_context_name)
        key_name = user_data.key_email + ":" + name_with_context

        if user_data.badges is None:
            user_data.badges = []

        user_data.badges.append(name_with_context)

        user_badge = models_badges.UserBadge.get_by_key_name(key_name)

        if user_badge is None:
            user_data.add_points(self.points)

            user_badge = models_badges.UserBadge(
                key_name=key_name,
                user=user_data.user,
                badge_name=self.name,
                target_context=target_context,
                target_context_name=target_context_name,
                points_earned=self.points)

            user_badge.put()

        # call notifications
        phantom_users.util_notify.update(user_data,
                                         None,
                                         threshold=False,
                                         isProf=False,
                                         gotBadge=True)
        UserNotifier.push_badge_for_user_data(user_data, user_badge)
Beispiel #2
0
    def complete_award_to(self,
                          user,
                          user_data,
                          target_context=None,
                          target_context_name=None):
        name_with_context = self.name_with_target_context(target_context_name)
        key_name = user.email() + ":" + name_with_context

        if user_data.badges is None:
            user_data.badges = []

        user_data.badges.append(name_with_context)

        user_badge = models_badges.UserBadge.get_by_key_name(key_name)

        if user_badge is None:
            user_data.add_points(self.points)

            user_badge = models_badges.UserBadge(
                key_name=key_name,
                user=user,
                badge_name=self.name,
                target_context=target_context,
                target_context_name=target_context_name,
                points_earned=self.points)

            user_badge.put()

        UserBadgeNotifier.push_for_user(user, user_badge)