Vital Stats Widget

The Vital Stats widget displays counts for categories you define. Each row has a count derived from saved searches. This is a highly customizable widget. You can determine how many rows are displayed and what each row reports. Each row is configured with a name (to describe what is being counted), the name of a saved search, and optionally a URL that points to search results. The count will be the number of distinct people records included in the results of the configured search.

To customize the widget for your own use, modify lines 8-12 of the Python script below, adding or deleting lines as necessary. Please note that, until you customize it, this widget is likely to fail on your database since you may not have the same status flags, saved searches, and queries used in the supplied sample code.

For each row, the first two parameters (name and saved search name) are required.

  1. The first name listed will be the name that reflects in the widget.

  2. Saved search names are matched by the exact name of the saved search in your database.

Optionally, if you want the name and count in the widget to be links to the search results, provide a URL as the third parameter. To get the URL, run the search and copy the second half of the URL – the part that follows your church database domain name. It will begin with /Query/ and conclude with a system-generated identifier. An example is provided in line 10 of the sample Python code below.

The widget utilizes an HTML file and a Python script as shown below. (No SQL script is needed.) Since the information in this widget is the same for all users, Caching should be set to all users.

HTML Code

Below is the HTML code for the Vital Stats widget. As supplied by TouchPoint, the file name is WidgetVitalStatsHTML.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<div class="box">
    <div class="box-title hidden-xs" style="border:0;">
        <h5>{{WidgetName}}</h5>
    </div>
    <a class="visible-xs-block" id="{{WidgetId}}-collapse" data-toggle="collapse" href="#{{WidgetId}}-section" aria-expanded="true" aria-controls="{{WidgetId}}-section">
        <div class="box-title">
            <h5><i class="fa fa-chevron-circle-right"></i>&nbsp;&nbsp;{{WidgetName}}</h5>
        </div>
    </a>
    <div class="collapse in" id="{{WidgetId}}-section">
        {{#ifGT results.Count 0}}
            <ul class="list-group bordered">
                {{#each results}}
                    {{#ifEqual name "Total"}}
                        <li class="list-group-item"><strong>{{name}}</strong><a href="{{url}}" class="badge badge-primary" style="float:right;font-weight:bold;">{{count}}</a></li>
                    {{else}}
                        <li class="list-group-item"><a href="{{url}}">{{name}}</a><a href="{{url}}" style="float:right;">{{count}}</a></li>
                    {{/ifEqual}}
                {{/each}}
            </ul>
        {{else}}
            <div class="box-content"></div>
        {{/ifGT}}
    </div>
</div>

Python Script

Below is the Python script for the Vital Stats widget. As supplied by TouchPoint, the file name is WidgetVitalStatsPython.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import re
# You can report summary numbers for any status flag or saved search you have set up with this widget
# Example data is below, to use put the name you want to appear in the widget, followed by the status flag code or saved search name on each line
# You can also use multiple status flag codes in a line by separating them with a comma - this will show the number of people that have ALL of the specified flags
# You can link the number to any url as well with a third parameter

statusFlags = [
    ( "Community Group", "MbrshpDecision" ),
    ( "Leaders", "ServeIn"),
    ( "Volunteers", "Volunteers", "/Query/f9449433-f972-46b0-95ab-ce142b5d54cb"),
    ( "New Visitors", "FirstTimeGuests" ),
]

def Get():
    results = []
    template = Data.HTMLContent
    
    for item in statusFlags:
        flag = model.DynamicData()
        flag.name = item[0]
        flag.flag = item[1]
        if re.search('^F\d+(,F\d+)*$',item[1]) is None:
            flag.count = q.QueryCount(item[1])
        else:
            flag.count = q.StatusCount(item[1])
        if len(item) > 2:
            flag.url = item[2]
        else:
            flag.url = '#'
        results.append(flag)
    
    Data.results = results
    print model.RenderTemplate(template)
Get()

Latest Update

06/15/2026

Updated Python script to match current deployed version