Touchpoint Software Documentation | Misc

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.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)
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]
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.

© 2018 TouchPoint Software, LLC.  All rights reserved.