Пример #1
0
    def merge_person_info(self, other):
        from indico.modules.events.contributions.models.persons import AuthorType
        for column_name in {'_title', 'affiliation', 'address', 'phone', 'first_name', 'last_name'}:
            value = getattr(self, column_name) or getattr(other, column_name)
            setattr(self, column_name, value)

        for event_link in other.event_links:
            existing_event_link = next((link for link in self.event_links if link.event_id == event_link.event_id),
                                       None)
            if existing_event_link is None:
                event_link.person = self
            else:
                other.event_links.remove(event_link)

        for abstract_link in other.abstract_links:
            existing_abstract_link = next((link for link in self.abstract_links
                                           if link.abstract_id == abstract_link.abstract_id), None)

            if existing_abstract_link is None:
                abstract_link.person = self
            else:
                existing_abstract_link.is_speaker |= abstract_link.is_speaker
                existing_abstract_link.author_type = AuthorType.get_highest(existing_abstract_link.author_type,
                                                                            abstract_link.author_type)
                other.abstract_links.remove(abstract_link)

        for contribution_link in other.contribution_links:
            existing_contribution_link = next((link for link in self.contribution_links
                                               if link.contribution_id == contribution_link.contribution_id), None)

            if existing_contribution_link is None:
                contribution_link.person = self
            else:
                existing_contribution_link.is_speaker |= contribution_link.is_speaker
                existing_contribution_link.author_type = AuthorType.get_highest(existing_contribution_link.author_type,
                                                                                contribution_link.author_type)
                other.contribution_links.remove(contribution_link)

        for subcontribution_link in other.subcontribution_links:
            existing_subcontribution_link = next(
                (link for link in self.subcontribution_links
                 if link.subcontribution_id == subcontribution_link.subcontribution_id), None)
            if existing_subcontribution_link is None:
                subcontribution_link.person = self
            else:
                other.subcontribution_links.remove(subcontribution_link)

        for session_block_link in other.session_block_links:
            existing_session_block_link = next((link for link in self.session_block_links
                                                if link.session_block_id == session_block_link.session_block_id),
                                               None)
            if existing_session_block_link is None:
                session_block_link.person = self
            else:
                other.session_block_links.remove(session_block_link)

        db.session.flush()
Пример #2
0
    def merge_person_info(self, other):
        from indico.modules.events.contributions.models.persons import AuthorType
        for column_name in {'_title', 'affiliation', 'address', 'phone', 'first_name', 'last_name'}:
            value = getattr(self, column_name) or getattr(other, column_name)
            setattr(self, column_name, value)

        for event_link in other.event_links:
            existing_event_link = next((link for link in self.event_links if link.event_id == event_link.event_id),
                                       None)
            if existing_event_link is None:
                event_link.person = self
            else:
                db.session.delete(event_link)

        for abstract_link in other.abstract_links:
            existing_abstract_link = next((link for link in self.abstract_links
                                           if link.abstract_id == abstract_link.abstract_id), None)

            if existing_abstract_link is None:
                abstract_link.person = self
            else:
                existing_abstract_link.is_speaker |= abstract_link.is_speaker
                existing_abstract_link.author_type = AuthorType.get_highest(existing_abstract_link.author_type,
                                                                            abstract_link.author_type)
                db.session.delete(abstract_link)

        for contribution_link in other.contribution_links:
            existing_contribution_link = next((link for link in self.contribution_links
                                               if link.contribution_id == contribution_link.contribution_id), None)

            if existing_contribution_link is None:
                contribution_link.person = self
            else:
                existing_contribution_link.is_speaker |= contribution_link.is_speaker
                existing_contribution_link.author_type = AuthorType.get_highest(existing_contribution_link.author_type,
                                                                                contribution_link.author_type)
                db.session.delete(contribution_link)

        for subcontribution_link in other.subcontribution_links:
            existing_subcontribution_link = next(
                (link for link in self.subcontribution_links
                 if link.subcontribution_id == subcontribution_link.subcontribution_id), None)
            if existing_subcontribution_link is None:
                subcontribution_link.person = self
            else:
                db.session.delete(subcontribution_link)

        for session_block_link in other.session_block_links:
            existing_session_block_link = next((link for link in self.session_block_links
                                                if link.session_block_id == session_block_link.contribution_id),
                                               None)
            if existing_session_block_link is None:
                session_block_link.person = self
            else:
                db.session.delete(session_block_link)

        db.session.flush()
Пример #3
0
    def _migrate_abstract_persons(self, abstract, zodb_abstract):
        old_persons = defaultdict(lambda: {
            'is_speaker': False,
            'author_type': AuthorType.none
        })
        for old_person in zodb_abstract._coAuthors:
            old_persons[old_person]['author_type'] = AuthorType.secondary
        for old_person in zodb_abstract._primaryAuthors:
            old_persons[old_person]['author_type'] = AuthorType.primary
        for old_person in zodb_abstract._speakers:
            old_persons[old_person]['is_speaker'] = True

        person_links_by_person = {}
        for person, roles in old_persons.iteritems():
            person_link = self._person_link_from_legacy(person)
            person_link.author_type = roles['author_type']
            person_link.is_speaker = roles['is_speaker']
            try:
                existing = person_links_by_person[person_link.person]
            except KeyError:
                person_links_by_person[person_link.person] = person_link
            else:
                author_type = AuthorType.get_highest(existing.author_type,
                                                     person_link.author_type)
                new_flags = '{}{}{}'.format(
                    'P' if person_link.author_type == AuthorType.primary else
                    '_', 'S' if person_link.author_type == AuthorType.secondary
                    else '_', 's' if person_link.is_speaker else '_')
                existing_flags = '{}{}{}'.format(
                    'P' if existing.author_type == AuthorType.primary else '_',
                    'S' if existing.author_type == AuthorType.secondary else
                    '_', 's' if existing.is_speaker else '_')
                if person_link.author_type == author_type and existing.author_type != author_type:
                    # the new one has the higher author type -> use that one
                    person_link.author_type = author_type
                    person_link.is_speaker |= existing.is_speaker
                    person_links_by_person[person_link.person] = person_link
                    self.print_warning(
                        '%[blue!]Abstract {}: %[yellow]Author {} already exists '
                        '(%[magenta]{} [{}] %[yellow]/ %[green]{} [{}]%[yellow])'
                        .format(abstract.friendly_id,
                                existing.person.full_name, existing.full_name,
                                existing_flags, person_link.full_name,
                                new_flags))
                    existing.person = None  # cut the link to an already-persistent object
                else:
                    # the existing one has the higher author type -> use that one
                    existing.author_type = author_type
                    existing.is_speaker |= person_link.is_speaker
                    self.print_warning(
                        '%[blue!]Abstract {}: %[yellow]Author {} already exists '
                        '(%[green]{} [{}]%[yellow] / %[magenta]{} [{}]%[yellow])'
                        .format(abstract.friendly_id,
                                existing.person.full_name, existing.full_name,
                                existing_flags, person_link.full_name,
                                new_flags))
                    person_link.person = None  # cut the link to an already-persistent object

        abstract.person_links.extend(person_links_by_person.viewvalues())
Пример #4
0
    def _migrate_abstract_persons(self, abstract, zodb_abstract):
        old_persons = defaultdict(lambda: {'is_speaker': False, 'author_type': AuthorType.none})
        for old_person in zodb_abstract._coAuthors:
            old_persons[old_person]['author_type'] = AuthorType.secondary
        for old_person in zodb_abstract._primaryAuthors:
            old_persons[old_person]['author_type'] = AuthorType.primary
        for old_person in zodb_abstract._speakers:
            old_persons[old_person]['is_speaker'] = True

        person_links_by_person = {}
        for person, roles in old_persons.iteritems():
            person_link = self._event_person_from_legacy(person)
            person_link.author_type = roles['author_type']
            person_link.is_speaker = roles['is_speaker']
            try:
                existing = person_links_by_person[person_link.person]
            except KeyError:
                person_links_by_person[person_link.person] = person_link
            else:
                author_type = AuthorType.get_highest(existing.author_type, person_link.author_type)
                new_flags = '{}{}{}'.format('P' if person_link.author_type == AuthorType.primary else '_',
                                            'S' if person_link.author_type == AuthorType.secondary else '_',
                                            's' if person_link.is_speaker else '_')
                existing_flags = '{}{}{}'.format('P' if existing.author_type == AuthorType.primary else '_',
                                                 'S' if existing.author_type == AuthorType.secondary else '_',
                                                 's' if existing.is_speaker else '_')
                if person_link.author_type == author_type and existing.author_type != author_type:
                    # the new one has the higher author type -> use that one
                    person_link.author_type = author_type
                    person_link.is_speaker |= existing.is_speaker
                    person_links_by_person[person_link.person] = person_link
                    self.importer.print_warning(cformat('%{blue!}Abstract {}: {yellow}Author {} already exists '
                                                        '(%{magenta}{} [{}] %{yellow}/ %{green}{} [{}]%{yellow})')
                                                .format(abstract.friendly_id, existing.person.full_name,
                                                        existing.full_name, existing_flags,
                                                        person_link.full_name, new_flags),
                                                event_id=self.event.id)
                    existing.person = None  # cut the link to an already-persistent object
                else:
                    # the existing one has the higher author type -> use that one
                    existing.author_type = author_type
                    existing.is_speaker |= person_link.is_speaker
                    self.importer.print_warning(cformat('%{blue!}Abstract {}: {yellow}Author {} already exists '
                                                        '(%{green}{} [{}]%{yellow} / %{magenta}{} [{}]%{yellow})')
                                                .format(abstract.friendly_id, existing.person.full_name,
                                                        existing.full_name, existing_flags,
                                                        person_link.full_name, new_flags),
                                                event_id=self.event.id)
                    person_link.person = None  # cut the link to an already-persistent object

        abstract.person_links.extend(person_links_by_person.viewvalues())