Vital Stats Widget

The Vital Stats widget displays counts for categories you define. Each row has a count derived from status flags or 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), a Status Flag or the name of a single 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 6-10 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 status flag or saved search) are required. 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 number. 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.

Video

Below is a short video demonstrating some of the features of this widget.


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
# 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 name or saved search name on each line
# You can link the number to any url as well with a third parameter

statusFlags = [
    ( "Decisions", "MbrshpDecision" ),
    ( "Leaders", "ServeIn"),
    ( "Seniors", "seniors", "https://trialdb.tpsdb.com/Query/e2c2fde2-c6db-478c-b81a-20f64050dcd5"),
    ( "New Visitors", "ActiveAttender" ),
    ( "Connected", "Connected" ),
]

def Get():
    results = []
    template = Data.HTMLContent
    
    for item in statusFlags:
        flag = model.DynamicData()
        flag.name = item[0]
        flag.flag = item[1]
        flag.count = q.QueryCount(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 11/08/2022

Changes to reflect new status flag naming scheme.