def _get_person_link(self, data): person_link = super()._get_person_link(data) roles = data.get('roles', []) person_link.is_speaker = 'speaker' in roles person_link.author_type = next( (AuthorType.get(a) for a in roles if AuthorType.get(a)), AuthorType.none) return person_link
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()
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()
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())
def __init__(self, *args, **kwargs): self.author_types = AuthorType.serialize() self.allow_authors = kwargs.pop('allow_authors', kwargs['_form'].event.type == 'conference') self.allow_submitters = kwargs.pop('allow_submitters', True) self.show_empty_coauthors = kwargs.pop('show_empty_coauthors', True) self.default_author_type = kwargs.pop('default_author_type', AuthorType.none) self.default_is_submitter = kwargs.pop('default_is_submitter', True) self.default_is_speaker = True super(ContributionPersonLinkListField, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.author_types = AuthorType.serialize() self.allow_authors = kwargs.pop('allow_authors', kwargs['_form'].event.type == 'conference') self.allow_submitters = kwargs.pop('allow_submitters', True) self.show_empty_coauthors = kwargs.pop('show_empty_coauthors', True) self.default_author_type = kwargs.pop('default_author_type', AuthorType.none) self.default_is_submitter = kwargs.pop('default_is_submitter', True) self.default_is_speaker = True super(ContributionPersonLinkListField, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.author_types = AuthorType.serialize() self.allow_authors = kwargs.pop("allow_authors", kwargs["_form"].event.type == "conference") self.allow_submitters = kwargs.pop("allow_submitters", True) self.show_empty_coauthors = kwargs.pop("show_empty_coauthors", True) self.default_author_type = kwargs.pop("default_author_type", AuthorType.none) self.default_is_submitter = kwargs.pop("default_is_submitter", True) self.default_is_speaker = True super(ContributionPersonLinkListField, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.author_types = AuthorType.serialize() self.allow_authors = True self.allow_submitters = False self.show_empty_coauthors = kwargs.pop('show_empty_coauthors', True) self.default_author_type = kwargs.pop('default_author_type', AuthorType.none) self.default_is_submitter = False self.default_is_speaker = False self.require_primary_author = True super(AbstractPersonLinkListField, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.author_types = AuthorType.serialize() self.allow_authors = True self.allow_submitters = False self.show_empty_coauthors = kwargs.pop('show_empty_coauthors', True) self.default_author_type = kwargs.pop('default_author_type', AuthorType.none) self.default_is_submitter = False self.default_is_speaker = False self.require_primary_author = True super(AbstractPersonLinkListField, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.author_types = AuthorType.serialize() self.allow_authors = True self.allow_submitters = False self.show_empty_coauthors = kwargs.pop('show_empty_coauthors', True) self.default_author_type = kwargs.pop('default_author_type', AuthorType.none) self.default_is_submitter = False self.default_is_speaker = False self.require_primary_author = True self.sort_by_last_name = True self.disable_user_search = kwargs.pop('disable_user_search', False) super().__init__(*args, **kwargs)
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())