Exemple #1
0
 def test_validate_age(self):
     assert utils.validate_age('20') == '20'
     assert utils.validate_age(' 20 ') == '20'
     assert utils.validate_age(u'20') == '20'
     assert utils.validate_age('20-30') == '20-30'
     assert utils.validate_age('20 - 30') == '20-30'
     assert utils.validate_age(u'20〜30') == '20-30'
     assert utils.validate_age(u'20 ー 30') == '20-30'
     assert utils.validate_age('20 !') == ''
     assert utils.validate_age('2 0') == ''
Exemple #2
0
 def test_validate_age(self):
     assert utils.validate_age('20') == '20'
     assert utils.validate_age(' 20 ') == '20'
     assert utils.validate_age(u'20') == '20'
     assert utils.validate_age('20-30') == '20-30'
     assert utils.validate_age('20 - 30') == '20-30'
     assert utils.validate_age(u'20〜30') == '20-30'
     assert utils.validate_age(u'20 ー 30') == '20-30'
     assert utils.validate_age('20 !') == ''
     assert utils.validate_age('2 0') == ''
Exemple #3
0
def create_person(repo, fields):
    """Creates a Person entity in the given repository with the given field
    values.  If 'fields' contains a 'person_record_id', calling put() on the
    resulting entity will overwrite any existing (original or clone) record
    with the same person_record_id.  Otherwise, a new original person record is
    created in the given repository."""
    person_fields = dict(
        entry_date=get_utcnow(),
        expiry_date=validate_datetime(fields.get('expiry_date')),
        author_name=strip(fields.get('author_name')),
        author_email=strip(fields.get('author_email')),
        author_phone=strip(fields.get('author_phone')),
        source_name=strip(fields.get('source_name')),
        source_url=strip(fields.get('source_url')),
        source_date=validate_datetime(fields.get('source_date')),
        full_name=strip(fields.get('full_name')),
        given_name=strip(fields.get('given_name')),
        family_name=strip(fields.get('family_name')),
        alternate_names=strip(fields.get('alternate_names')),
        description=strip(fields.get('description')),
        sex=validate_sex(fields.get('sex')),
        date_of_birth=validate_approximate_date(fields.get('date_of_birth')),
        age=validate_age(fields.get('age')),
        home_street=strip(fields.get('home_street')),
        home_neighborhood=strip(fields.get('home_neighborhood')),
        home_city=strip(fields.get('home_city')),
        home_state=strip(fields.get('home_state')),
        home_postal_code=strip(fields.get('home_postal_code')),
        home_country=strip(fields.get('home_country')),
        photo_url=strip(fields.get('photo_url')),
        profile_urls=strip(fields.get('profile_urls')),
    )

    # For PFIF 1.3 or older, populate full_name (it was an optional field
    # before), using given_name and family_name if it is empty.
    if not person_fields['full_name'].strip():
        person_fields['full_name'] = get_full_name(
            person_fields['given_name'],
            person_fields['family_name'],
            config.Configuration(repo))
    # TODO(liuhsinwen): Separate existed and non-existed record id and
    # increment person counter for new records
    record_id = strip(fields.get('person_record_id'))
    if record_id:  # create a record that might overwrite an existing one
        if is_clone(repo, record_id):
            return Person.create_clone(repo, record_id, **person_fields)
        else:
            return Person.create_original_with_record_id(
                repo, record_id, **person_fields)
    else:  # create a new original record
        # TODO(liuhsinwen): fix performance problem by incrementing the counter
        # by the number of upload records
        # UsageCounter.increment_person_counter(repo)
        return Person.create_original(repo, **person_fields)
Exemple #4
0
def create_person(repo, fields):
    """Creates a Person entity in the given repository with the given field
    values.  If 'fields' contains a 'person_record_id', calling put() on the
    resulting entity will overwrite any existing (original or clone) record
    with the same person_record_id.  Otherwise, a new original person record is
    created in the given repository."""
    person_fields = dict(
        entry_date=get_utcnow(),
        expiry_date=validate_datetime(fields.get('expiry_date')),
        author_name=strip(fields.get('author_name')),
        author_email=strip(fields.get('author_email')),
        author_phone=strip(fields.get('author_phone')),
        source_name=strip(fields.get('source_name')),
        source_url=strip(fields.get('source_url')),
        source_date=validate_datetime(fields.get('source_date')),
        full_name=strip(fields.get('full_name')),
        given_name=strip(fields.get('given_name')),
        family_name=strip(fields.get('family_name')),
        alternate_names=strip(fields.get('alternate_names')),
        description=strip(fields.get('description')),
        sex=validate_sex(fields.get('sex')),
        date_of_birth=validate_approximate_date(fields.get('date_of_birth')),
        age=validate_age(fields.get('age')),
        home_street=strip(fields.get('home_street')),
        home_neighborhood=strip(fields.get('home_neighborhood')),
        home_city=strip(fields.get('home_city')),
        home_state=strip(fields.get('home_state')),
        home_postal_code=strip(fields.get('home_postal_code')),
        home_country=strip(fields.get('home_country')),
        photo_url=strip(fields.get('photo_url')),
        profile_urls=strip(fields.get('profile_urls')),
    )

    # For PFIF 1.3 or older, populate full_name (it was an optional field
    # before), using given_name and family_name if it is empty.
    if not person_fields['full_name'].strip():
        person_fields['full_name'] = get_full_name(
            person_fields['given_name'], person_fields['family_name'],
            config.Configuration(repo))
    # TODO(liuhsinwen): Separate existed and non-existed record id and
    # increment person counter for new records
    record_id = strip(fields.get('person_record_id'))
    if record_id:  # create a record that might overwrite an existing one
        if is_clone(repo, record_id):
            return Person.create_clone(repo, record_id, **person_fields)
        else:
            return Person.create_original_with_record_id(
                repo, record_id, **person_fields)
    else:  # create a new original record
        # TODO(liuhsinwen): fix performance problem by incrementing the counter
        # by the number of upload records
        # UsageCounter.increment_person_counter(repo)
        return Person.create_original(repo, **person_fields)
Exemple #5
0
def create_person(subdomain, fields):
    """Creates a Note entity in the given subdomain's repository with the given
    field values.  If 'fields' contains a 'person_record_id', calling put() on
    the resulting entity will overwrite any existing (original or clone) record
    with the same person_record_id.  Otherwise, a new original person record is
    created in the given subdomain."""
    person_fields = dict(
        entry_date=get_utcnow(),
        expiry_date=validate_datetime(fields.get('expiry_date')),
        author_name=strip(fields.get('author_name')),
        author_email=strip(fields.get('author_email')),
        author_phone=strip(fields.get('author_phone')),
        source_name=strip(fields.get('source_name')),
        source_url=strip(fields.get('source_url')),
        source_date=validate_datetime(fields.get('source_date')),
        full_name=strip(fields.get('full_name')),
        first_name=strip(fields.get('first_name')),
        last_name=strip(fields.get('last_name')),
        sex=validate_sex(fields.get('sex')),
        date_of_birth=validate_approximate_date(fields.get('date_of_birth')),
        age=validate_age(fields.get('age')),
        home_street=strip(fields.get('home_street')),
        home_neighborhood=strip(fields.get('home_neighborhood')),
        home_city=strip(fields.get('home_city')),
        home_state=strip(fields.get('home_state')),
        # Fall back to 'home_zip' for backward compatibility with PFIF 1.1.
        home_postal_code=strip(
            fields.get('home_postal_code', fields.get('home_zip'))),
        home_country=strip(fields.get('home_country')),
        photo_url=strip(fields.get('photo_url')),
        other=fields.get('other')
    )

    record_id = strip(fields.get('person_record_id'))
    if record_id:  # create a record that might overwrite an existing one
        if is_clone(subdomain, record_id):
            return Person.create_clone(subdomain, record_id, **person_fields)
        else:
            return Person.create_original_with_record_id(
                subdomain, record_id, **person_fields)
    else:  # create a new original record
        return Person.create_original(subdomain, **person_fields)
def create_person(fields, requires_key=True):
  """Creates a Person entity with the given field values.  Note that storing
  the resulting entity will overwrite an existing entity with the same
  person_record_id, even in the home domain.  If no person_record_id is given,
  the resulting entity will get a new unique id in the home domain."""
  assert strip(fields.get('first_name')), 'first_name is required'
  assert strip(fields.get('last_name')), 'last_name is required'
  if requires_key:
    assert strip(fields.get('person_record_id')), 'person_record_id is required'
  person_constructor_dict = dict(
      entry_date=datetime.datetime.now(),
      author_name=strip(fields.get('author_name')),
      author_email=strip(fields.get('author_email')),
      author_phone=strip(fields.get('author_phone')),
      source_name=strip(fields.get('source_name')),
      source_url=strip(fields.get('source_url')),
      source_date=validate_datetime(fields.get('source_date')),
      first_name=strip(fields['first_name']),
      last_name=strip(fields['last_name']),
      sex=validate_sex(fields.get('sex')),
      date_of_birth=validate_approximate_date(fields.get('date_of_birth')),
      age=validate_age(fields.get('age')),
      home_street=strip(fields.get('home_street')),
      home_neighborhood=strip(fields.get('home_neighborhood')),
      home_city=strip(fields.get('home_city')),
      home_state=strip(fields.get('home_state')),
      home_zip=strip(fields.get('home_postal_code', fields.get('home_zip'))),
      home_country=strip(fields.get('home_country')),
      photo_url=strip(fields.get('photo_url')),
      other=fields.get('other'),
      last_update_date=datetime.datetime.now(),
  )

  # If the person_record_id is supplied, set the new entity's key accordingly.
  record_id = strip(fields.get('person_record_id'))
  if record_id:
    if is_original(record_id):  # original record
      person_constructor_dict['key'] = key_from_record_id(record_id, 'Person')
    else:  # clone record
      person_constructor_dict['key_name'] = record_id

  return Person(**person_constructor_dict)
Exemple #7
0
def create_person(subdomain, fields):
    """Creates a Note entity in the given subdomain's repository with the given
    field values.  If 'fields' contains a 'person_record_id', calling put() on
    the resulting entity will overwrite any existing (original or clone) record
    with the same person_record_id.  Otherwise, a new original person record is
    created in the given subdomain."""
    person_fields = dict(
        entry_date=get_utcnow(),
        expiry_date=validate_datetime(fields.get('expiry_date')),
        author_name=strip(fields.get('author_name')),
        author_email=strip(fields.get('author_email')),
        author_phone=strip(fields.get('author_phone')),
        source_name=strip(fields.get('source_name')),
        source_url=strip(fields.get('source_url')),
        source_date=validate_datetime(fields.get('source_date')),
        full_name=strip(fields.get('full_name')),
        first_name=strip(fields.get('first_name')),
        last_name=strip(fields.get('last_name')),
        sex=validate_sex(fields.get('sex')),
        date_of_birth=validate_approximate_date(fields.get('date_of_birth')),
        age=validate_age(fields.get('age')),
        home_street=strip(fields.get('home_street')),
        home_neighborhood=strip(fields.get('home_neighborhood')),
        home_city=strip(fields.get('home_city')),
        home_state=strip(fields.get('home_state')),
        # Fall back to 'home_zip' for backward compatibility with PFIF 1.1.
        home_postal_code=strip(
            fields.get('home_postal_code', fields.get('home_zip'))),
        home_country=strip(fields.get('home_country')),
        photo_url=strip(fields.get('photo_url')),
        other=fields.get('other'))

    record_id = strip(fields.get('person_record_id'))
    if record_id:  # create a record that might overwrite an existing one
        if is_clone(subdomain, record_id):
            return Person.create_clone(subdomain, record_id, **person_fields)
        else:
            return Person.create_original_with_record_id(
                subdomain, record_id, **person_fields)
    else:  # create a new original record
        return Person.create_original(subdomain, **person_fields)