def create_note(repo, fields): """Creates a Note entity in the given repository with the given field values. If 'fields' contains a 'note_record_id', calling put() on the resulting entity will overwrite any existing (original or clone) record with the same note_record_id. Otherwise, a new original note record is created in the given repository.""" assert strip(fields.get('person_record_id')), 'person_record_id is required' assert strip(fields.get('source_date')), 'source_date is required' note_fields = dict( person_record_id=strip(fields['person_record_id']), linked_person_record_id=strip(fields.get('linked_person_record_id')), author_name=strip(fields.get('author_name')), author_email=strip(fields.get('author_email')), author_phone=strip(fields.get('author_phone')), source_date=validate_datetime(fields.get('source_date')), status=validate_status(fields.get('status')), author_made_contact=validate_boolean(fields.get('author_made_contact')), email_of_found_person=strip(fields.get('email_of_found_person')), phone_of_found_person=strip(fields.get('phone_of_found_person')), last_known_location=strip(fields.get('last_known_location')), text=fields.get('text'), photo_url=fields.get('photo_url'), entry_date=get_utcnow(), ) record_id = strip(fields.get('note_record_id')) if record_id: # create a record that might overwrite an existing one if is_clone(repo, record_id): return Note.create_clone(repo, record_id, **note_fields) else: return Note.create_original_with_record_id( repo, record_id, **note_fields) else: # create a new original record return Note.create_original(repo, **note_fields)
def create_note(subdomain, fields): """Creates a Note entity in the given subdomain's repository with the given field values. If 'fields' contains a 'note_record_id', calling put() on the resulting entity will overwrite any existing (original or clone) record with the same note_record_id. Otherwise, a new original note record is created in the given subdomain.""" assert strip( fields.get('person_record_id')), 'person_record_id is required' assert strip(fields.get('source_date')), 'source_date is required' note_fields = dict( person_record_id=strip(fields['person_record_id']), linked_person_record_id=strip(fields.get('linked_person_record_id')), author_name=strip(fields.get('author_name')), author_email=strip(fields.get('author_email')), author_phone=strip(fields.get('author_phone')), source_date=validate_datetime(fields.get('source_date')), status=validate_status(fields.get('status')), found=validate_boolean(fields.get('found')), email_of_found_person=strip(fields.get('email_of_found_person')), phone_of_found_person=strip(fields.get('phone_of_found_person')), last_known_location=strip(fields.get('last_known_location')), text=fields.get('text'), entry_date=get_utcnow(), ) record_id = strip(fields.get('note_record_id')) if record_id: # create a record that might overwrite an existing one if is_clone(subdomain, record_id): return Note.create_clone(subdomain, record_id, **note_fields) else: return Note.create_original_with_record_id(subdomain, record_id, **note_fields) else: # create a new original record return Note.create_original(subdomain, **note_fields)
def create_note(fields, requires_key=True): """Creates a Note entity with the given field values. Note that storing the resulting entity will overwrite an existing entity with the same note_record_id, even in the home domain. If no note_record_id is given, the resulting entity will get a new unique id in the home domain.""" if requires_key: assert strip(fields.get('note_record_id')), 'note_record_id is required' assert strip(fields.get('person_record_id')), 'person_record_id is required' note_constructor_dict = dict( person_record_id=strip(fields['person_record_id']), linked_person_record_id=strip(fields.get('linked_person_record_id')), author_name=strip(fields.get('author_name')), author_email=strip(fields.get('author_email')), author_phone=strip(fields.get('author_phone')), source_date=validate_datetime(fields.get('source_date')), status=validate_status(fields.get('status')), found=validate_boolean(fields.get('found')), email_of_found_person=strip(fields.get('email_of_found_person')), phone_of_found_person=strip(fields.get('phone_of_found_person')), last_known_location=strip(fields.get('last_known_location')), text=fields.get('text'), ) # If the note_record_id is supplied, set the new entity's key accordingly. record_id = strip(fields.get('note_record_id')) if record_id: if is_original(record_id): # original record note_constructor_dict['key'] = key_from_record_id(record_id, 'Note') else: # clone record note_constructor_dict['key_name'] = record_id return Note(**note_constructor_dict)
def create_note(repo, fields): """Creates a Note entity in the given repository with the given field values. If 'fields' contains a 'note_record_id', calling put() on the resulting entity will overwrite any existing (original or clone) record with the same note_record_id. Otherwise, a new original note record is created in the given repository.""" assert strip( fields.get('person_record_id')), 'person_record_id is required' assert strip(fields.get('source_date')), 'source_date is required' note_fields = dict( person_record_id=strip(fields['person_record_id']), linked_person_record_id=strip(fields.get('linked_person_record_id')), author_name=strip(fields.get('author_name')), author_email=strip(fields.get('author_email')), author_phone=strip(fields.get('author_phone')), source_date=validate_datetime(fields.get('source_date')), status=validate_status(fields.get('status')), author_made_contact=validate_boolean( fields.get('author_made_contact')), email_of_found_person=strip(fields.get('email_of_found_person')), phone_of_found_person=strip(fields.get('phone_of_found_person')), last_known_location=strip(fields.get('last_known_location')), text=fields.get('text'), photo_url=fields.get('photo_url'), entry_date=get_utcnow(), ) # TODO(liuhsinwen): Separate existed and non-existed record id and # increment note counter for new records record_id = strip(fields.get('note_record_id')) if record_id: # create a record that might overwrite an existing one if is_clone(repo, record_id): return Note.create_clone(repo, record_id, **note_fields) else: return Note.create_original_with_record_id(repo, record_id, **note_fields) else: # create a new original record # TODO(liuhsinwen): fix performance problem by incrementing the counter # by the number of upload notes # UsageCounter.increment_note_counter(repo) return Note.create_original(repo, **note_fields)