rattail.people

People Handler

See also People Handler.

class rattail.people.PeopleHandler(config, **kwargs)[source]

Base class and default implementation for people handlers.

add_address(person, type=None, street=None, street2=None, city=None, state=None, zipcode=None, invalid=False, preferred=False, **kwargs)[source]

Add a physical/mailing address record for the person.

Parameters:
  • person – Reference to a Person record.

  • type – Type of address to add.

  • street – Street (line 1) for the address.

  • street2 – Street (line 2) for the address.

  • city – City for the address.

  • state – State for the address.

  • zipcode – Zipcode for the address.

  • invalid – Boolean indicating the address is known to not be valid.

  • preferred – Boolean indicating that this should (or not) be the “preferred” address for the person.

add_email(person, address, type='Home', invalid=False, preferred=False, **kwargs)[source]

Add a email record for the person.

Parameters:
  • person – Reference to a Person record.

  • address – Actual email address to add.

  • type – Type of email address to add.

  • invalid – Boolean indicating the address is known to not be valid.

  • preferred – Boolean indicating that this should (or not) be the “preferred” email address for the person.

add_phone(person, number, type='Home', preferred=False, **kwargs)[source]

Add a phone record for the person.

Parameters:
  • person – Reference to a Person record.

  • number – Actual phone number to add.

  • type – Type of phone number to add.

  • preferred – Boolean indicating that this should be the new “preferred” number for the person.

address_is_invalid(person, address, **kwargs)[source]

Returns a boolean indicating if the given person’s address is invalid.

Parameters:
  • person – Reference to a person.

  • address – Reference to a person’s address.

ensure_address(person, **kwargs)[source]

Returns the default address record associated with the given person, creating it first if necessary.

get_merge_preview_data(person, **kwargs)[source]

Must return a data dictionary for the given person, which can be presented to the user during a merge preview.

get_merge_preview_fields(**kwargs)[source]

Returns a sequence of fields which will be used during a merge preview.

get_person(obj, **kwargs)[source]

Retrieve the Person related to the given object.

This is a rather fundamental method, in that it is called by several other methods, both within this handler as well as others. There is even a shortcut to it, accessible via rattail.app.AppHandler.get_person().

Its purpose is to navigate relationships as needed, to get at the “default” person associated with the object. Depending on how the app tracks relationships, this logic may need to vary.

make_person(**kwargs)[source]

Make and return a new Person instance.

mark_address_invalid(person, address, invalid, **kwargs)[source]

Mark the person’s address as invalid.

Parameters:
  • person – Reference to a person.

  • address – Reference to a person’s address.

  • invalid – Boolean indicating “invalid” status for person’s address.

merge_update_keeping_object(removing, keeping)[source]

Update the object to be kept, with any relevant data from the object to be removed, in the context of a merge.

normalize_full_name(first, last, **kwargs)[source]

Normalize a “full” name based on the given first and last names. Tries to be smart about collapsing whitespace etc.

Parameters:
  • first – First name.

  • last – Last name.

Returns:

First and last name combined.

notify_of_merge_request(merge)[source]

Send an email alert regarding a new merge request.

perform_merge(removing, keeping, **kwargs)[source]

Perform an actual merge of the 2 given objects.

Parameters:
  • removing – Object which should be removed.

  • keeping – Object which should be kept.

quickie_lookup(entry, session)[source]

Attempt to locate a person based on the given entry. By default this will do a lookup based on the configured Customer key field. Override as needed.

request_merge(user, removing_uuid, keeping_uuid, **kwargs)[source]

Submit an officical merge request for two Person records.

The caller must obviously specify which is to be kept and which removed, but really this is arbitrary, as the user performing the merge is free to swap them around.

resolve_person(pending, person, user, **kwargs)[source]

Resolve a pending person.

Parameters:
  • pending – Reference to a PendingCustomer instance.

  • person – Reference to a Person instance.

  • user – Reference to the User responsible.

satisfy_merge_requests(removing, keeping, user)[source]

If there was a merge request(s) for this pair, mark it complete.

update_address(person, address, **kwargs)[source]

Update the given address with the given data.

update_email(person, email, **kwargs)[source]

Update a email record for the person.

Parameters:
  • person – Reference to a Person record.

  • email – Reference to the PersonEmailAddress record to update.

  • address – Actual email address.

  • type – Type of email address.

  • invalid – Boolean indicating the address is known to not be valid.

  • preferred – Boolean indicating that this should (or not) be the “preferred” address for the person.

update_names(person, **kwargs)[source]

Update name(s) for the given person.

Parameters:
  • person – Reference to a Person record.

  • first – First name for the person.

  • preferred_first – Preferred first name for the person.

  • middle – Middle name for the person.

  • last – Last name for the person.

  • full – Full (display) name for the person.

update_phone(person, phone, **kwargs)[source]

Update a phone record for the person.

Parameters:
  • person – Reference to a Person record.

  • phone – Reference to the PersonPhoneNumber record to update.

  • number – Actual phone number.

  • type – Type of phone number.

  • preferred – Boolean indicating that this should be the new “preferred” number for the person.

why_not_merge(removing, keeping, **kwargs)[source]

Evaluate the given merge candidates and if there is a reason not to merge them, return that reason.

Parameters:
  • removing – Person record which will be removed, should the merge happen.

  • keeping – Person record which will be kept, should the merge happen.

Returns:

String indicating reason not to merge, or None.

rattail.people.get_people_handler(config, **kwargs)[source]

Create and return the configured PeopleHandler instance.

Warning

This function is deprecated; please use get_people_handler() instead.