Пример #1
0
def create_abstract_review(abstract, track, user, review_data, questions_data):
    review = AbstractReview(abstract=abstract, track=track, user=user)
    review.populate_from_dict(review_data)
    log_data = {}
    for question in abstract.event.abstract_review_questions:
        value = int(questions_data['question_{}'.format(question.id)])
        review.ratings.append(AbstractReviewRating(question=question, value=value))
        log_data[question.text] = value
    db.session.flush()
    logger.info("Abstract %s received a review by %s for track %s", abstract, user, track)
    log_data.update({
        'Track': track.title,
        'Action': orig_string(review.proposed_action.title),
        'Comment': review.comment
    })
    if review.proposed_action == AbstractAction.accept:
        log_data['Contribution type'] = (review.proposed_contribution_type.name if review.proposed_contribution_type
                                         else None)
    elif review.proposed_action == AbstractAction.change_tracks:
        log_data['Other tracks'] = sorted(t.title for t in review.proposed_tracks)
    elif review.proposed_action in {AbstractAction.mark_as_duplicate, AbstractAction.merge}:
        log_data['Other abstract'] = review.proposed_related_abstract.verbose_title
    abstract.event.log(EventLogRealm.management, EventLogKind.positive, 'Abstracts',
                       'Abstract {} reviewed'.format(abstract.verbose_title), user, data=log_data)
    return review
Пример #2
0
    def get_review_rating(self, review, allow_create=False):
        """Get the rating given in particular review.

        :param review: the review object
        :param allow_create: if there is not rating for that review a new one is created
        """
        results = [rating for rating in review.ratings if rating.question == self]
        rating = results[0] if results else None
        if rating is None and allow_create:
            rating = AbstractReviewRating(question=self, review=review)
        return rating
Пример #3
0
def test_abstract_review_scale_ratings(db, dummy_abstract, dummy_event, dummy_user,
                                       value, scale_min, scale_max, expected):
    from indico.modules.events.abstracts.controllers.management import RHManageAbstractReviewing
    abstracts_reviewing_settings.set(dummy_event, 'scale_lower', 0)
    abstracts_reviewing_settings.set(dummy_event, 'scale_upper', 5)

    question = AbstractReviewQuestion(field_type='rating', title='Rating')
    dummy_event.abstract_review_questions.append(question)
    review = AbstractReview(
        abstract=dummy_abstract, track=Track(title='Dummy Track', event=dummy_event),
        user=dummy_user, proposed_action=AbstractAction.accept
    )
    rating = AbstractReviewRating(question=question, value=value)
    review.ratings.append(rating)
    db.session.flush()

    rh = RHManageAbstractReviewing()
    rh.event = dummy_event
    rh._scale_ratings(scale_min, scale_max)
    assert rating.value == expected
Пример #4
0
    def _migrate_abstract_reviews(self, abstract, old_abstract):
        if not hasattr(old_abstract, '_trackJudgementsHistorical'):
            self.print_warning(
                '%[blue!]Abstract {} %[yellow]had no judgment history!%[reset]'
                .format(old_abstract._id))
            return

        history = old_abstract._trackJudgementsHistorical
        if not hasattr(history, 'iteritems'):
            self.print_warning(
                'Abstract {} had corrupt judgment history ({}).'.format(
                    old_abstract._id, history))
            return
        for track_id, old_judgments in history.iteritems():
            seen_judges = set()
            for old_judgment in old_judgments:
                if old_judgment is None:
                    continue
                if old_judgment.__class__.__name__ == 'AbstractUnMarkedAsDuplicated':
                    # we don't have "unmarked as duplicate" anymore
                    continue

                try:
                    track = self.event_ns.track_map_by_id[int(
                        old_judgment._track.id)]
                except KeyError:
                    self.print_warning(
                        '%[blue!]Abstract {} %[yellow]judged in invalid track {}%[reset]'
                        .format(old_abstract._id, int(old_judgment._track.id)))
                    continue

                judge = (self.global_ns.avatar_merged_user.get(
                    old_judgment._responsible.id)
                         if old_judgment._responsible else None)
                if not judge:
                    self.print_warning(
                        '%[blue!]Abstract {} %[yellow]had an empty judge ({})!%[reset]'
                        .format(old_abstract._id, old_judgment))
                    continue
                elif judge in seen_judges:
                    self.print_warning(
                        "%[blue!]Abstract {}: %[yellow]judge '{}' seen more than once ({})!%[reset]"
                        .format(old_abstract._id, judge, old_judgment))
                    continue

                seen_judges.add(judge)

                try:
                    created_dt = as_utc(old_judgment._date)
                except AttributeError:
                    created_dt = self.event.start_dt
                review = AbstractReview(created_dt=created_dt,
                                        proposed_action=self.ACTION_MAP[
                                            old_judgment.__class__.__name__],
                                        comment=convert_to_unicode(
                                            old_judgment._comment))
                if review.proposed_action == AbstractAction.accept:
                    review.proposed_contribution_type = self.event_ns.legacy_contribution_type_map.get(
                        old_judgment._contribType)
                elif review.proposed_action == AbstractAction.change_tracks:
                    review.proposed_tracks = {
                        self.event_ns.track_map[t]
                        for t in old_judgment._proposedTracks
                        if t in self.event_ns.track_map
                    }
                elif review.proposed_action == AbstractAction.mark_as_duplicate:
                    self.event_ns.as_duplicate_reviews[
                        review] = old_judgment._originalAbst

                review.user = judge
                review.track = track

                answered_questions = set()
                for old_answer in getattr(old_judgment, '_answers', []):
                    if old_answer._question in answered_questions:
                        self.print_warning(
                            "%[blue!]Abstract {}: %[yellow]question answered more than once!"
                            .format(abstract.friendly_id))
                        continue
                    try:
                        question = self.question_map[old_answer._question]
                    except KeyError:
                        question = self._migrate_question(old_answer._question,
                                                          is_deleted=True)
                        self.print_warning(
                            "%[blue!]Abstract {}: %[yellow]answer for deleted question"
                            .format(abstract.friendly_id))
                    rating = AbstractReviewRating(
                        question=question,
                        value=self._convert_scale(old_answer))
                    review.ratings.append(rating)
                    answered_questions.add(old_answer._question)

                abstract.reviews.append(review)
Пример #5
0
    def _migrate_abstract_reviews(self, abstract, zodb_abstract, old_abstract,
                                  as_duplicate_reviews):
        old_judgments = {(j.track_id, j.judge): j
                         for j in old_abstract.judgments}
        for old_track_id, zodb_judgments in getattr(
                zodb_abstract, '_trackJudgementsHistorical', {}).iteritems():
            seen_judges = set()
            for zodb_judgment in zodb_judgments:
                if zodb_judgment is None:
                    continue
                if zodb_judgment.__class__.__name__ == 'AbstractUnMarkedAsDuplicated':
                    # we don't have "unmarked as duplicate" anymore
                    continue
                try:
                    track = self.track_map_by_id[int(zodb_judgment._track.id)]
                except KeyError:
                    self.importer.print_warning(cformat(
                        '%{blue!}Abstract {} {yellow}judged in invalid track {}%{reset}'
                    ).format(zodb_abstract._id, int(zodb_judgment._track.id)),
                                                event_id=self.event.id)
                    continue
                judge = self._user_from_legacy(zodb_judgment._responsible)
                if not judge:
                    # self.importer.print_warning(
                    #     cformat('%{blue!}Abstract {} {yellow}had an empty judge ({})!%{reset}').format(
                    #         zodb_abstract._id, zodb_judgment), event_id=self.event.id)
                    continue
                elif judge in seen_judges:
                    # self.importer.print_warning(
                    #     cformat("%{blue!}Abstract {}: {yellow}judge '{}' seen more than once ({})!%{reset}")
                    #         .format(zodb_abstract._id, judge, zodb_judgment), event_id=self.event.id)
                    continue

                seen_judges.add(judge)
                try:
                    created_dt = as_utc(zodb_judgment._date)
                except AttributeError:
                    created_dt = self.event.start_dt
                review = AbstractReview(created_dt=created_dt,
                                        proposed_action=self.ACTION_MAP[
                                            zodb_judgment.__class__.__name__],
                                        comment=convert_to_unicode(
                                            zodb_judgment._comment))
                if review.proposed_action == AbstractAction.accept:
                    try:
                        old_judgment = old_judgments[int(old_track_id), judge]
                    except KeyError:
                        self.importer.print_error(cformat(
                            '%{yellow!}Abstract #{} has no new judgment for {} / {}'
                        ).format(abstract.friendly_id, int(old_track_id),
                                 judge),
                                                  event_id=self.event.id)
                        continue
                    review.proposed_contribution_type = old_judgment.accepted_type
                    review.proposed_track = self.track_map_by_id[
                        old_judgment.track_id]
                elif review.proposed_action == AbstractAction.change_tracks:
                    review.proposed_tracks = {
                        self.track_map[t]
                        for t in zodb_judgment._proposedTracks
                    }
                elif review.proposed_action == AbstractAction.mark_as_duplicate:
                    as_duplicate_reviews.add(
                        (review, zodb_judgment._originalAbst))

                review.user = judge
                review.track = track

                answered_questions = set()
                for old_answer in getattr(zodb_judgment, '_answers', []):
                    if old_answer._question in answered_questions:
                        self.importer.print_warning(cformat(
                            "%{blue!}Abstract {}: {yellow}question answered more than once!"
                        ).format(abstract.friendly_id),
                                                    event_id=self.event.id)
                        continue
                    try:
                        question = self.question_map[old_answer._question]
                    except KeyError:
                        question = self._migrate_question(old_answer._question,
                                                          is_deleted=True)
                        self.importer.print_warning(cformat(
                            "%{blue!}Abstract {}: {yellow}answer for deleted question"
                        ).format(abstract.friendly_id),
                                                    event_id=self.event.id)
                    rating = AbstractReviewRating(
                        question=question,
                        value=self._convert_scale(old_answer))
                    review.ratings.append(rating)
                    answered_questions.add(old_answer._question)

                abstract.reviews.append(review)