Misc
=================
.. py:function:: model.AppendIfBoth(s1, join, s2)
:return: the resulting string
:rtype: str
:param str s1: the first string
:param str join: the text to join between the two strings
:param str s2: the second string
If both s1 and s2 have values, the concatenation of s1 + join + s2 will be returned,
otherwise just s1 is returned.
.. py:function:: model.CallScript(name)
:return: the output of the script from all the ``print`` statements
:rtype: str
:param str name: The name of the Python Script Special Content
.. py:function:: model.Content(name)
:return: The content
:rtype: str
:param str name: The name of the Content file
.. py:function:: model.CreateCustomView(view, sql)
:param str view: The name of the custom view to create
:param str sql: The SQL query that defines the view
Creates a custom view in the database. This function is restricted to users with both
"developer" and "admin" roles. The view name must be a single alphanumeric word.
The view will be created in the "custom" schema.
.. py:function:: model.CreateQueryTag(name, code)
:return: The count of people in the target
:rtype: int
:param str name: The name of the QueryTag
:param str code: 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.
.. py:function:: model.CsvReader(text)
:return: an object to use for reading the csv file
:rtype: CsvHelper.CsvReader
:param str text: The text of the csv content
Example::
csv = model.CsvReader(model.Data.file)
while csv.Read():
Date = model.ParseDate(csv['Date'])
Amount = csv['Amount']
.. py:function:: model.CsvReader(text, delimiter)
:return: an object to use for reading the csv file
:rtype: CsvHelper.CsvReader
:param str text: The text of the csv content
:param str delimiter: The character used to separate values in the CSV file
Similar to the standard CsvReader but allows specifying a custom delimiter.
.. py:function:: model.CsvReaderNoHeader(text)
:return: an object to use for reading the csv file
:rtype: CsvHelper.CsvReader
:param str text: The text of the csv content
Example::
csv = model.CsvReader(model.Data.file)
while csv.Read():
Date = model.ParseDate(csv[0])
Amount = csv[1]
.. py:function:: model.CustomStatementsFundIdList(name)
:return: the string with all fundids in a comma separated list.
:rtype: str
:param str name: the name of the FundList
.. seealso::
:doc:`/Finance/CustomStatements`
and :doc:`/CustomProgramming/TextScripts/CustomFundSets`
.. py:data:: model.CmsHost
:return: The string like "https://bellevue.tpsdb.com" for your church database.
:rtype: str
This is useful for producing links such as::
linktemplate='{2}'
link = linktemplate.format(model.CmsHost, peopleid, name)
.. py:data:: model.Data
:rtype: Dynamic Dictionary object, with keys as properties.
This object is available whenever a Python Script is run.
.. py:function:: model.DataHas(key)
:return: True if Data has a property for the specified key
:rtype: bool
:param str key: The name of the key (case sensitive)
Example::
Data.Test = "some words"
if DataHas("Test"):
print Data.Test
.. py:function:: model.DeleteQueryTags(namelike)
:param str namelike: The name of the QueryTag using % as wild card(s)
.. py:function:: model.DynamicData()
:return: a new DynamicData object
:rtype: 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 '
'
print dd
print '
'
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 ''
print dd
print 'The sum of num1 and num2 is:', dd.lev.num1 + dd.lev.num2
print '
'
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 (``.``).
.. py:function:: model.DynamicDataFromJson(json)
:return: the DynamicData object
:rtype: DynamicData
:param str json: 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.
.. py:function:: model.DynamicDataFromJsonArray(json)
:return: a list of DynamicData objects
:rtype: List
:param str json: the JSON array string to deserialize
Converts a JSON array string into a list of DynamicData objects.
.. py:function:: model.ElementList(array, name)
:return: a list of string values extracted from the specified property
:rtype: List
:param IEnumerable array: collection of DynamicData objects
:param str name: the property name to extract from each object
Extracts a specific property value from each DynamicData object in the collection
and returns them as a list of strings.
.. py:function:: model.FmtPhone(phone, *prefix)
:return: The formatted phone number, e.g. 901-555-1212.
:rtype: str
:param str phone: The phone number to format.
:param str prefix: \*Optional, Goes in front of the formatted number, e.g. `(c)` for cell phone.
.. py:function:: model.FmtZip(zipcode)
:return: The zip code formatted with "plus four" (e.g. 38018-2243 )
:rtype: str
:param str zipcode: The zipcode number to format.
.. py:function:: model.FormatJson(json)
:return: The formatted json
:rtype: str
:param str json: The compressed json string to be formatted
This adds indentation and newlines to a compressed json string making it easier to read.
.. py:function:: model.FormatJson(data)
:return: The formatted json
:rtype: str
:param dictionary data: 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.
.. py:data:: model.FromMorningBatch
:return: True if this script is being called from the Batch Service.
:rtype: bool
.. py:function:: model.GetCacheVariable(name)
:return: The value of the cached variable or an empty string if not found
:rtype: str
:param str name: The name of the cache variable to retrieve
Retrieves a value from the ASP.NET cache. Returns an empty string if the variable
doesn't exist or if called from a batch process.
.. py:function:: model.HtmlContent(name)
:return: The body of the HTML content saved in Special Content > HTML under name.
:rtype: str
:param str name: The name of the content
.. py:function:: model.JsonDeserialize(jsontext)
:return: The content of the returned result
:rtype: dynamic
:param str jsontext: The JSON text.
.. py:function:: model.JsonDeserialize2(jsontext)
:return: The content of the returned result
:rtype: List of dynamic: A Python List of Python Dictionary objects
:param str jsontext: The JSON text.
This method is designed to deserialize an array of json objects.
.. py:function:: model.JsonSerialize(obj)
:return: The object converted into a JSON string
:rtype: str
:param object obj: The object to be converted
.. py:function:: Markdown(text)
:return: The rendered HTML text
:rtype: str
:param str text: The markdown text
See https://www.markdownguide.org/
.. py:function:: model.Md5Hash(text)
:return: A hashed string
:rtype: str
:param str text: The string to be hashed
.. py:function:: model.RegexMatch(s, regex)
:return: The matched text
:rtype: str
:param str s: the target string to be searched for a match
:param str regex: the Regular Expression pattern to match on
.. py:function:: model.Replace(text, pattern, replacement)
:return: The new string with all occurrences of pattern in text replaced with replacement.
:rtype: str
:param str text: The entire string to be modified.
:param str pattern: The special text to be replaced.
:param str replacement: The replacement text.
.. py:function:: model.RestDelete(url, headers, *user, *password)
:return: The content of the returned result
:rtype: str
:param str url: The fully qualified URL of the REST endpoint
:param Dictionary headers: The data passed as headers (stored as a Python Dictionary object)
:param str user: The optional user name
:param str password: The optional password
The user and password are passed as a Basic Authentication string
The HTTP verb is DELETE
.. py:function:: model.RestGet(url, headers, *user, *password)
:return: The content of the returned result
:rtype: str
:param str url: The fully qualified URL of the REST endpoint
:param Dictionary headers: The data passed as headers (stored as a Python Dictionary object)
:param str user: The optional user name
:param str password: The optional password
The user and password are passed as a Basic Authentication string
The HTTP verb is GET.
.. py:function:: model.RestPost(url, headers, obj, *user, *password)
:return: The content of the returned result
:rtype: str
:param str url: The fully qualified URL of the REST endpoint
:param Dictionary headers: The data passed as headers (stored as a Python Dictionary object)
:param object obj: The body of the POST method
:param str user: The optional user name
:param str password: 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.
The content-type will be set to "application/x-www-form-urlencoded" unless the headers dictionary contains a key "Content-Type".
.. py:function:: model.RestPostJson(url, headers, obj, *user, *password)
:return: The content of the returned result
:rtype: str
:param str url: The fully qualified URL of the REST endpoint
:param Dictionary headers: The data passed as headers (stored as a Python Dictionary object)
:param object obj: The body of the POST method
:param str user: The optional user name
:param str password: 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.
.. py:function:: model.RestPostXml(url, headers, body, *user, *password)
:return: The content of the returned result
:rtype: str
:param str url: The fully qualified URL of the REST endpoint
:param Dictionary headers: The data passed as headers (stored as a Python Dictionary object)
:param str body: The XML body of the POST method
:param str user: The optional user name
:param str password: The optional password
The user and password are passed as a Basic Authentication string
The HTTP verb is POST.
The body will be sent as XML content with content-type "text/xml".
.. py:function:: model.SetCacheVariable(name, value)
:param str name: The name of the cache variable to set
:param str value: The value to store in the cache
Stores a value in the ASP.NET cache with a 1-minute expiration time.
This function has no effect when called from a batch process.
.. py:function:: model.Setting(name, def)
:return: The Setting value
:rtype: str
:param str name: The name of the Setting
:param str def: The optional default value, an empty string if not passed
.. py:function:: model.SetSetting(name, value)
:param str name: The name of the setting to set
:param object value: The value to store in the setting
Updates or creates a setting in the database with the specified name and value.
.. py:function:: model.SpaceCamelCase(s)
:return: the string with space separated words at each Capital letter.
:rtype: str
:param str s: the CamelCasedWords string to be expanded.
.. py:function:: model.SqlContent(name)
:return: The SQL content saved in Special Content > SQL Scripts
:rtype: str
:param str name: The name of the script
.. py:function:: model.TextContent(name)
:return: The text saved in Special Content > Text Content
:rtype: str
:param str name: The name of the text file
.. py:function:: model.TitleContent(name)
:return: The title attribute of the content saved in Special Content under name.
:rtype: str
:param str name: The name of the content
This is often used to store the Subject of an email represented by the content.
.. py:function:: model.Trim(s)
:return: The string with leading and trailing whitespace removed
:rtype: str
:param str s: The string to trim
Removes whitespace from the beginning and end of a string.
.. py:function:: model.UrlEncode(s)
:return: The URL-encoded string
:rtype: str
:param str s: The string to URL encode
Encodes a string to be used safely in a URL.
.. py:data:: model.UserName
:return: The username of the logged on user running the script.
:rtype: str
.. py:data:: model.UserPeopleId
:return: The PeopleId of the currently logged in user, or null if not available
:rtype: int?
This property provides access to the current user's PeopleId.
.. py:function:: model.UserIsInRole(role)
:return: True or False
:rtype: bool
:param str role: the role to check
.. py:function:: model.WriteContentHtml(name, text, *keyword)
:param str name: The name of the file
:param str text: The HTML content to be written
:param str keyword: Optional keyword to associate with the content
This function writes HTML content to an HTML file in Special Content.
If the file exists it will be overwritten.
Otherwise, a new file is created.
.. py:function:: model.WriteContentPython(name, script, *keyword)
:param str name: The name of the file
:param str script: The Python script to be written
:param str keyword: Optional keyword to associate with the content
This function writes Python script content to a Python Script file in Special Content.
If the file exists it will be overwritten.
Otherwise, a new file is created.
.. py:function:: model.WriteContentSql(name, sql, *keyword)
:param str name: The name of the file
:param str sql: The SQL code to be written
:param str keyword: Optional keyword to associate with the content
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.
.. py:function:: model.WriteContentText(name, text, *keyword)
:param str name: The name of the file
:param str text: The text to be written
:param str keyword: Optional keyword to associate with the content
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.
|
|
+--------------------+------------------+
| **Latest Update** | **3/28/2025** |
+--------------------+------------------+
Updated with missing functions and alphabetized.