Misc

model.CmsHost
Returns:The string like “https://bellevue.tpsdb.com” for your church database.
Return type:str

This is useful for producing links such as:

linktemplate='<a href="{0}/Person2/{1}">{2}</a>'
link = linktemplate.format(model.CmsHost, peopleid, name)
model.FromMorningBatch
Returns:True if this script is being called from the Batch Service.
Return type:bool
model.UserName
Returns:The username of the logged on user running the script.
Return type:str
model.Data
Return type:Dynamic Dictionary object, with keys as properties.

This object is available whenever a Python Script is run.

model.CallScript(name)
Returns:the output of the script from all the print statements
Return type:str
Parameters:name (str) – The name of the Python Script Special Content
model.Content(name)
Returns:The content
Return type:str
Parameters:name (str) – The name of the Content file
model.DataHas(key)
Returns:True if Data has a property for the specified key
Return type:bool
Parameters:key (str) – The name of the key (case sensitive)

Example:

Data.Test = "some words"
if DataHas("Test"):
    print Data.Test
model.DynamicData()
Returns:a new DynamicData object
Return type:DynamicData

This function returns a new DynamicData object that can be used in Python to hold data with name/value pairs.

The easiest way to explain is by examples of what it can do. Try the following code:

dd = model.DynamicData()
dd.value1 = "Value one"
dd.value2 = 123
print '<pre>'
print dd
print '</pre>'

When executed the following shows on the screen:

{
    "value1": "Value one",
    "value2": 123
}

So you are able to store arbitrary values into a DynamicData object in a very simple manner. The output of the print statement presents a representation of the data in JSON format.

Try this:

dd = model.DynamicData()
dd.title = 'This is a demonstration of using multiple levels'
dd.lev = model.DynamicData()
dd.lev.str = "This is in the second level"
dd.lev.num1 = 1
dd.lev.num2 = 2
print '<pre>'
print dd
print 'The sum of num1 and num2 is:', dd.lev.num1 + dd.lev.num2
print '</pre>'

When executed the following is printed to the screen:

{
    "title": "This is a demonstration of using multiple levels",
    "lev": {
        "str": "This is in the second level",
        "num1": 1,
        "num2": 2
    }
}
The sum of num1 and num2 is: 3

Note that there are two assignments of a DynamicData object. The second assiment is to dd.lev, a member of the first object. This way, nested heirarchys are simple and can hold complex and organized structures.

Note how dd.lev.num1 clearly shows the heirarchy from the first level (dd) to the second level (lev) through the dot notation (.).

model.FmtPhone(phone, *prefix)
Returns:

The formatted phone number, e.g. 901-555-1212.

Return type:

str

Parameters:
  • phone (str) – The phone number to format.
  • prefix (str) – *Optional, Goes in front of the formatted number, e.g. (c) for cell phone.
model.FmtZip(zipcode)
Returns:The zip code formatted with “plus four” (e.g. 38018-2243 )
Return type:str
Parameters:zipcode (str) – The zipcode number to format.
model.HtmlContent(name)
Returns:The body of the HTML content saved in Special Content > HTML under name.
Return type:str
Parameters:name (str) – The name of the content
model.SqlContent(name)
Returns:The SQL content saved in Special Content > SQL Scripts
Return type:str
Parameters:name (str) – The name of the script
model.TextContent(name)
Returns:The text saved in Special Content > Text Content
Return type:str
Parameters:name (str) – The name of the text file
model.TitleContent(name)
Returns:The title attribute of the content saved in Special Content under name.
Return type:str
Parameters:name (str) – The name of the content

This is often used to store the Subject of an email represented by the content.

model.Replace(text, pattern, replacement)
Returns:

The new string with all occurrences of pattern in text replaced with replacement.

Return type:

str

Parameters:
  • text (str) – The entire string to be modified.
  • pattern (str) – The special text to be replaced.
  • replacement (str) – The replacement text.
Markdown(text)
Returns:The rendered HTML text
Return type:str
Parameters:text (str) – The markdown text

See https://www.markdownguide.org/

RegexMatch(s, regex)
Returns:

The matched text

Return type:

str

Parameters:
  • s (str) – the target string to be searched for a match
  • regex (str) – the Regular Expression pattern to match on
RestGet(url, headers, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint
  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)
  • user (str) – The optional user name
  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is GET.

RestPost(url, headers, obj, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint
  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)
  • obj (object) – The body of the POST method
  • user (str) – The optional user name
  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is POST.

The obj will be converted to a string and passed to the REST POST endpoint.

RestPostJson(url, headers, obj, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint
  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)
  • obj (object) – The body of the POST method
  • user (str) – The optional user name
  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is POST.

The body will be Serialized into a JSON string.

RestDelete(url, headers, *user, *password)
Returns:

The content of the returned result

Return type:

str

Parameters:
  • url (str) – The fully qualified URL of the REST endpoint
  • headers (Dictionary) – The data passed as headers (stored as a Python Dictionary object)
  • user (str) – The optional user name
  • password (str) – The optional password

The user and password are passed as a Basic Authentication string The HTTP verb is DELETE

JsonDeserialize(jsontext)
Returns:The content of the returned result
Return type:dynamic
Parameters:jsontext (str) – The JSON text.
JsonDeserialize2(jsontext)
Returns:The content of the returned result
Return type:List of dynamic: A Python List of Python Dictionary objects
Parameters:jsontext (str) – The JSON text.

This method is designed to deserialize an array of json objects.

JsonSerialize(obj)
Returns:The object converted into a JSON string
Return type:str
Parameters:obj (object) – The object to be converted
Setting(name, def)
Returns:

The Setting value

Return type:

str

Parameters:
  • name (str) – The name of the Setting
  • def (str) – The optional default value, an empty string if not passed
FormatJson(json)
Returns:The formatted json
Return type:str
Parameters:json (str) – The compressed json string to be formatted

This adds indentation and newlines to a compressed json string making it easier to read.

FormatJson(data)
Returns:The formatted json
Return type:str
Parameters:data (dictionary) – The Python object that should be formatted as Json

Works the same as previous except that you pass in a Python object instead of a json string.

Md5Hash(text)
Returns:A hashed string
Return type:str
Parameters:text (str) – The string to be hashed
CreateQueryTag(name, code)
Returns:

The count of people in the target

Return type:

int

Parameters:
  • name (str) – The name of the QueryTag
  • code (str) – The Search Builder code to be run

This creates a special type of tag called QueryTag. It uses the same table that holds all other tags. But this type is only managed (created and deleted) with a Python script. If QueryTags will be used for multiple purposes, it is important to name the tags with a common prefix for a given purpose or project. This way it will be easy to delete a project’s query tags to start over without disturbing other projects.

DeleteQueryTags(namelike)
Parameters:namelike (str) – The name of the QueryTag using % as wild card(s)
WriteContentSql(name, sql)
Parameters:
  • name (str) – The name of the file
  • sql (str) – The SQL code to be written

This function writes Sql content to a Sql Script file in Special Content. If the file exists it will be overwritten. Otherwise, a new file is created.

WriteContentText(name, text)
Parameters:
  • name (str) – The name of the file
  • text (str) – The text to be written

This function writes text to a Text file in Special Content. If the file exists it will be overwritten. Otherwise, a new file is created.

CsvReader(text)
Returns:an object to use for reading the csv file
Return type:CsvHelper.CsvReader
Parameters:text (str) – The text of the csv content

Example:

csv = model.CsvReader(model.Data.file)
while csv.Read():
    Date = model.ParseDate(csv['Date'])
    Amount = csv['Amount']
CsvReaderNoHeader(text)
Returns:an object to use for reading the csv file
Return type:CsvHelper.CsvReader
Parameters:text (str) – The text of the csv content

Example:

csv = model.CsvReader(model.Data.file)
while csv.Read():
    Date = model.ParseDate(csv[0])
    Amount = csv[1]
model.AppendIfBoth(s1, join, s2)
Returns:

the resulting string

Return type:

str

Parameters:
  • s1 (str) – the first string
  • join (str) – the text to join between the two strings
  • s2 (str) – the second string

If both s1 and s2 have values, the concatenation of s1 + join + s2 will be returned, otherwise just s1 is returned.

model.DynamicDataFromJson(json)
Returns:the DynamicData object
Return type:DynamicData
Parameters:json (str) – the string of JSON code

Example:

json = '''
{
    "Member": {
        "RowType": "Member",
        "FamilyCnt": 2746,
        "RecurringCnt": 110,
        "MonthlyAmt": 76831.975
    },
    "NonMember": {
        "RowType": "NonMember",
        "FamilyCnt": 2887,
        "RecurringCnt": 20,
        "MonthlyAmt": 8372.175
    },
    "Combined": {
        "RowType": "Combined",
        "FamilyCnt": 5633,
        "RecurringCnt": 130,
        "MonthlyAmt": 85204.15
    },
    "Created": "3/11/19 3:51 PM"
}
'''
data = model.DynamicDataFromJson(json)
print data.Created
print data.NonMember.MonthlyAmt

The two print statements will output the appropriate values.

model.CustomStatementsFundIdList(name)
Returns:the string with all fundids in a comma separated list.
Return type:str
Parameters:name (str) – the name of the FundList
model.SpaceCamelCase(s)
Returns:the string with space separated words at each Capital letter.
Return type:str
Parameters:s (str) – the CamelCasedWords string to be expanded.
model.UserIsInRole(role)
Returns:True or False
Return type:bool
Parameters:role (str) – the role to check

© 2019 TouchPoint Software, LLC.  All rights reserved.