GivingHouseholds Python Script¶
Suggestion: Right click the link and select the “Open link in a new window” item then arrange your windows you can view side by side.
Explanation of the Code¶
Line 1
allows only those with the role Finance to run this script.
Line 3
allows the code to use .NET DateTime functionality.
Line 5
determines if the user is an Admin.
See model.UserIsInRole()
Line 7
loads the HTML template for the report script used to collect the data for the report.
See model.TextContent()
.
Line 10
loads the previously cached DynamicData structure constructed during the GivingHouseholdsData Python Script process.
Lines 12-14
define a function which formats a numeric value with commas and decimal places.
Returns an empty string if the numeric value is not defined (None).
Lines 16-17
perform a safe division, avoiding divide by zero.
Note
The SafeDiv function is converted to a percentage using the format function.
The format string {:.1%}
automatically divides by 100 and formats the value with one decimal place of accuracy.
Lines 19-39
define a function called NewRowAdmin which returns a single role of table columns for the report.
The table rows created in this function are suitable for an Admin as there are links to use for reconciliation.
The variables isheadcode and isfamilygiver are QueryCode partials appended to
the querycode parameter all used in a hyperlink to construct a SearchBuilder query on the fly for reconciliation.
See Lines 24 and 25
.
Line 36
contains a link to be able to see the individual contributions using a specific purpose feature of Contribution Search.
Lines 41-59
define a function called NewRow which returns the table row like the previous function,
without the reconciliation and validation links, suitable for a non-Admin user.
Lines 61-93
define a function called GetTable which returns the entire table for a given date range.
There are three rows in the table, one for Members, one for NonMembers, and one for Both Combined.
Lines 95-97
create the three tables, one for each of the date ranges:
‘Year to Date’, ‘Last 30 Days’, and ‘Last 365 Days’.
Line 99
The final step is to incorporate the three tables into the HTML template by replacing HTML comments
for each date range: <!--ytd-->
, <!--d30-->
, and <!--d365-->
. The resulting HTML is printed to the screen.