forked from move-coop/parsons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable email dict to be passed to VAN.upsert_person() (move-coop#963)
This allows for greater configurability of email data when upserting person records in EveryAction. This change is backwards compatible, but allows, for example, setting emails to not be subscribed by default when loading into EveryAction.
- Loading branch information
1 parent
cc84320
commit 044708d
Showing
1 changed file
with
15 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from parsons.utilities import json_format | ||
from typing import Union, List, Dict | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -197,7 +198,7 @@ def upsert_person( | |
first_name=None, | ||
last_name=None, | ||
date_of_birth=None, | ||
email=None, | ||
email: Union[str, List[Dict[str, Union[str, bool]]], None] = None, | ||
phone=None, | ||
phone_type=None, | ||
street_number=None, | ||
|
@@ -227,8 +228,10 @@ def upsert_person( | |
The person's last name | ||
dob: str | ||
ISO 8601 formatted date of birth (e.g. ``1981-02-01``) | ||
email: str | ||
The person's email address | ||
email: Union[str, List[Dict[str, Union[str, bool]]], None] | ||
The person's email address or a list of email dicts. | ||
e.g. [{'email': '[email protected]', 'isSubscribed': False}] | ||
See https://docs.everyaction.com/reference/people-common-models#email | ||
phone: str | ||
Phone number of any type (Work, Cell, Home) | ||
phone_type: str | ||
|
@@ -298,7 +301,7 @@ def _people_search( | |
first_name=None, | ||
last_name=None, | ||
date_of_birth=None, | ||
email=None, | ||
email: Union[str, List[Dict[str, Union[str, bool]]], None] = None, | ||
phone=None, | ||
phone_type="H", | ||
street_number=None, | ||
|
@@ -320,7 +323,14 @@ def _people_search( | |
|
||
# Will fail if empty dicts are provided, hence needed to add if exist | ||
if email: | ||
json["emails"] = [{"email": email}] | ||
if isinstance(email, str): | ||
json["emails"] = [{"email": email}] | ||
elif isinstance(email, list): | ||
json["emails"] = email | ||
else: | ||
raise ValueError( | ||
f"Unexpected data type for email argument: {type(email)}" | ||
) | ||
if phone: # To Do: Strip out non-integers from phone | ||
json["phones"] = [{"phoneNumber": phone, "phoneType": phone_type}] | ||
if date_of_birth: | ||
|