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.get( 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) review.proposed_track = self.event_ns.track_map_by_id.get( track_id) elif review.proposed_action == AbstractAction.change_tracks: review.proposed_tracks = { self.event_ns.track_map.get(t) for t in old_judgment._proposedTracks } 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)
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)
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)