コード例 #1
0
ファイル: event_abstracts.py プロジェクト: pmart123/indico
 def _event_person_from_legacy(self, old_person):
     data = dict(first_name=convert_to_unicode(old_person._firstName),
                 last_name=convert_to_unicode(old_person._surName),
                 _title=self.USER_TITLE_MAP.get(
                     getattr(old_person, '_title', ''), UserTitle.none),
                 affiliation=convert_to_unicode(old_person._affilliation),
                 address=convert_to_unicode(old_person._address),
                 phone=convert_to_unicode(old_person._telephone))
     email = strict_sanitize_email(old_person._email)
     if email:
         person = (self.event_persons_by_email.get(email)
                   or self.event_persons_by_user.get(
                       self.importer.all_users_by_email.get(email)))
     else:
         person = self.event_persons_noemail_by_data.get(
             (data['first_name'], data['last_name'], data['affiliation']))
     if not person:
         user = self.importer.all_users_by_email.get(email)
         person = EventPerson(event_new=self.event,
                              user=user,
                              email=email,
                              **data)
         if email:
             self.event_persons_by_email[email] = person
         if user:
             self.event_persons_by_user[user] = person
         if not email and not user:
             self.event_persons_noemail_by_data[(
                 person.first_name, person.last_name,
                 person.affiliation)] = person
     person_link = AbstractPersonLink(person=person)
     person_link.populate_from_dict(data)
     return person_link
コード例 #2
0
 def _create(abstract, first_name, last_name, email, affiliation, title, is_speaker, author_type):
     person = create_event_person(abstract.event, first_name=first_name, last_name=last_name, email=email,
                                  affiliation=affiliation, title=title)
     link = AbstractPersonLink(abstract=abstract, person=person, is_speaker=is_speaker, author_type=author_type)
     db.session.add(person)
     db.session.flush()
     return link
コード例 #3
0
 def _person_link_from_legacy(self, old_person):
     person = self.event_person_from_legacy(old_person)
     person_link = AbstractPersonLink(person=person)
     data = dict(first_name=convert_to_unicode(old_person._firstName),
                 last_name=convert_to_unicode(old_person._surName),
                 _title=self.USER_TITLE_MAP.get(getattr(old_person, '_title', ''), UserTitle.none),
                 affiliation=convert_to_unicode(old_person._affilliation),
                 address=convert_to_unicode(old_person._address),
                 phone=convert_to_unicode(old_person._telephone))
     person_link.populate_from_dict(data)
     return person_link
コード例 #4
0
def test_unused_event_person(db, dummy_user, dummy_event, create_contribution,
                             create_subcontribution, create_abstract):
    person = EventPerson.create_from_user(dummy_user, event=dummy_event)
    assert not person.has_links

    dummy_event.person_links.append(EventPersonLink(person=person))
    db.session.flush()
    assert person.has_links

    dummy_event.person_links.clear()
    db.session.flush()
    assert not person.has_links

    set_feature_enabled(dummy_event, 'abstracts', True)
    abstract = create_abstract(dummy_event,
                               'Dummy abstract',
                               submitter=dummy_user,
                               person_links=[
                                   AbstractPersonLink(
                                       person=person,
                                       is_speaker=True,
                                       author_type=AuthorType.primary)
                               ])
    assert person.has_links
    abstract.is_deleted = True
    assert not person.has_links

    contrib = create_contribution(
        dummy_event,
        'Dummy contribution',
        person_links=[ContributionPersonLink(person=person, is_speaker=True)])
    assert person.has_links
    contrib.is_deleted = True
    assert not person.has_links
    db.session.delete(contrib)

    contrib = create_contribution(dummy_event,
                                  'Dummy contribution',
                                  person_links=[])
    assert not person.has_links
    create_subcontribution(contrib,
                           'Dummy subcontribution',
                           person_links=[
                               SubContributionPersonLink(person=person,
                                                         is_speaker=True)
                           ])
    assert person.has_links

    contrib.is_deleted = True
    assert not person.has_links

    db.session.delete(contrib)
    assert not person.has_links
コード例 #5
0
ファイル: abstract_list.py プロジェクト: javfg/indico
 def clone_fields(self, abstract):
     field_names = [
         'title', 'description', 'submission_comment',
         'submitted_for_tracks', 'submitted_contrib_type'
     ]
     field_data = {f: getattr(abstract, f) for f in field_names}
     person_links = []
     link_attrs = get_simple_column_attrs(AbstractPersonLink)
     for old_link in abstract.person_links:
         link = AbstractPersonLink(person=old_link.person)
         link.populate_from_attrs(old_link, link_attrs)
         person_links.append(link)
     field_data['person_links'] = person_links
     for f in abstract.field_values:
         field_data[f'custom_{f.contribution_field_id}'] = f.data
     return field_data
コード例 #6
0
ファイル: operations.py プロジェクト: wasm-network/indico
def _merge_person_links(target_abstract, source_abstract):
    """
    Merge `person_links` of different abstracts.

    Add to `target_abstract` new `AbstractPersonLink`s whose `EventPerson`
    exists in the `source_abstract` but is not yet in the `target_abstract`.

    :param target_abstract: The target abstract (to which the links should then be added)
    :param source_abstract: The source abstract
    """
    new_links = set()
    source_links = source_abstract.person_links
    source_link_map = defaultdict(set)
    for link in source_links:
        source_link_map[link.person.id].add(link)
    unique_persons = {link.person
                      for link in source_links} - {
                          link.person
                          for link in target_abstract.person_links
                      }
    sort_position = max(link.display_order
                        for link in target_abstract.person_links) + 1
    persons_sorted = sort_position > 1

    for person in unique_persons:
        for source_link in source_link_map[person.id]:
            link = AbstractPersonLink(person=person,
                                      author_type=source_link.author_type,
                                      is_speaker=source_link.is_speaker)
            # if the persons in the abstract are sorted, add at the end
            # otherwise, keep alphabetical order
            if persons_sorted:
                link.display_order = sort_position
                sort_position += 1
            else:
                link.display_order = 0
            new_links.add(link)
            for column_name in {
                    '_title', '_affiliation', '_address', '_phone',
                    '_first_name', '_last_name'
            }:
                setattr(link, column_name, getattr(source_link, column_name))

    # Add new links in order
    for link in sorted(new_links, key=attrgetter('display_order_key')):
        target_abstract.person_links.append(link)