Beispiel #1
0
    def insert_feedback(text, feedback_type, feedback_parent, user_data):
        """Create a Feedback entity.

        Questions and comments must have videos as their parents and answers
        must have questions as their parents.

        Arguments:
            text: the question text.
            feedback_type: either FeedbackType's Question, Answer, or Comment
            feedback_parent: the video/question below which this entity was
                             posted.
            user_data: the user_data who asked the question.
        """
        feedback = Feedback(parent=user_data)
        feedback.types = [feedback_type]

        feedback.set_author(user_data)
        feedback.content = text

        if feedback_type == FeedbackType.Answer:
            feedback.targets = [
                feedback_parent.video_key(),
                feedback_parent.key()
            ]
        else:
            feedback.targets = [feedback_parent.key()]

        feedback.low_quality_score = Heuristics.get_low_quality_score(
            text, feedback_type)

        if user_data.discussion_banned:
            # Hellbanned users' posts are automatically hidden
            feedback.deleted = True

        feedback.put()

        if util_badges.update_with_triggers([BadgeTriggerType.POST],
                                            user_data=user_data,
                                            feedback=feedback):
            user_data.put()

        # Create notification for new answers if the user isn't hellbanned
        # and if the answer author isn't the question author.
        if (feedback_type == FeedbackType.Answer
                and not user_data.discussion_banned
                and feedback.author_user_id != feedback_parent.author_user_id):
            FeedbackNotification.create_notification_for_new_answer(
                feedback_parent, feedback)

        return feedback
    def insert_feedback(text, feedback_type, feedback_parent, user_data):
        """Create a Feedback entity.

        Questions and comments must have videos as their parents and answers
        must have questions as their parents.

        Arguments:
            text: the question text.
            feedback_type: either FeedbackType's Question, Answer, or Comment
            feedback_parent: the video/question below which this entity was
                             posted.
            user_data: the user_data who asked the question.
        """
        feedback = Feedback(parent=user_data)
        feedback.types = [feedback_type]

        feedback.set_author(user_data)
        feedback.content = text

        if feedback_type == FeedbackType.Answer:
            feedback.targets = [feedback_parent.video_key(),
                feedback_parent.key()]
        else:
            feedback.targets = [feedback_parent.key()]

        feedback.low_quality_score = Heuristics.get_low_quality_score(text,
            feedback_type)

        if user_data.discussion_banned:
            # Hellbanned users' posts are automatically hidden
            feedback.deleted = True

        feedback.put()

        if util_badges.update_with_triggers([BadgeTriggerType.POST],
                user_data=user_data, feedback=feedback):
            user_data.put()

        # Create notification for new answers if the user isn't hellbanned
        # and if the answer author isn't the question author.
        if (feedback_type == FeedbackType.Answer and
                not user_data.discussion_banned and
                feedback.author_user_id != feedback_parent.author_user_id):
            FeedbackNotification.create_notification_for_new_answer(
                feedback_parent, feedback)

        return feedback
Beispiel #3
0
    def award_author_badges(entity, author, author_stats):
        awarded = util_badges.update_with_triggers(
            [BadgeTriggerType.VOTEE],
            user_data=author, user_discussion_stats=author_stats)

        possible_badges = util_badges.badges_with_context_type(
            BadgeContextType.FEEDBACK)

        for badge in possible_badges:
            if not badge.is_already_owned_by(
                    user_data=author, feedback=entity):
                if badge.is_satisfied_by(
                        user_data=author, feedback=entity):
                    badge.award_to(user_data=author, feedback=entity)
                    awarded = True

        if awarded:
            author.put()
Beispiel #4
0
    def award_author_badges(entity, author, author_stats):
        awarded = util_badges.update_with_triggers(
            [BadgeTriggerType.VOTEE],
            user_data=author,
            user_discussion_stats=author_stats)

        possible_badges = util_badges.badges_with_context_type(
            BadgeContextType.FEEDBACK)

        for badge in possible_badges:
            if not badge.is_already_owned_by(user_data=author,
                                             feedback=entity):
                if badge.is_satisfied_by(user_data=author, feedback=entity):
                    badge.award_to(user_data=author, feedback=entity)
                    awarded = True

        if awarded:
            author.put()