FPU Packet Pickup Process

Return to Financial Peace University Packet Pickup Project.

When someone scans the barcode or clicks the action button, the following Python script is run to process the results. An explanation follows the script.

Note

This file should be located under Admin > Special Content > Text tab, and be named FPUPacketProcess.py. The Text tab is used to prevent anyone from trying to run this file directly as it must be run as a part of the main entry point.

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def Process():
    if '-' not in model.Data.wandtarget:
        return
    
    a = model.Data.wandtarget.split('-')
    oid = a[0]
    pid = a[1]
    
    p = model.GetPerson(pid)
    sp = model.GetSpouse(pid)
    if sp is not None:
        spid = sp.PeopleId
    o = model.GetOrganization(oid)
    inorg = model.InOrg(pid, oid)
    
    if p == None:
        print "<h3 class='alert alert-danger'>Person {0} not Found</h3>".format(pid)
    
    if o == None:
        print "<h3 class='alert alert-danger'>Organization {0} not Found</h3>".format(oid)
    
    if not inorg:
        print "<h3 class='alert alert-danger'>Person {0} not in {1}</h3>".format(pid, oid)
    
    if p is not None and o is not None:
        print '''
        <table class="table">
        <tr><td align="right">Org:</td><td><b>{0}</b></td></tr>
        <tr><td align="right">Name:</td><td><b>{1}</b></td></tr>
        '''.format(o.name, p.Name)
    
        if not inorg:
            print '</table>'
            return
    
        if sp is not None and model.InOrg(spid, oid):
            print '''
            <tr><td align="right">Spouse:</td><td><b>{0}</b></td></tr>
            '''.format(sp.Name)
    
        print '</table>'
    
        if model.Data.paidoption == "markpaid":
            model.AddSubGroup(pid, oid, "pay online")
            print "<h3 class='alert alert-warning'>Marked Now As Paid</h3>"
        elif model.Data.paidoption == "marknotpaid":
            model.RemoveSubGroup(pid, oid, "pay online")
            print "<h3 class='alert alert-warning'>Marked Now As Not Paid</h3>"
        else:
            if model.InSubGroup(pid, oid, "pay online"):
                print "<h3 class='alert alert-success'>Packet Paid For Already</h3>"
            elif sp is not None and model.InSubGroup(spid, oid, "pay online"):
                print "<h3 class='alert alert-success'>Packet Paid For by Spouse Already</h3>"
            else:
                print "<h3 class='alert alert-danger'>Packet Not Paid For</h3>"
    
        if model.Data.pickedup == "notpickedup":
            model.RemoveSubGroup(pid, oid, "packet-picked-up")
            print "<h3 class='alert alert-warning'>Packet Now Marked As Not Picked Up</h3>"
        else:
            if model.InSubGroup(pid, oid, "packet-picked-up"):
                print "<h3 class='alert alert-danger'>Packet Already Picked Up</h3>"
            elif sp is not None and model.InSubGroup(spid, oid, "packet-picked-up"):
                print "<h3 class='alert alert-danger'>Packet Picked Up by Spouse Already</h3>"
            else:
                model.AddSubGroup(pid, oid, "packet-picked-up")
                print "<h3 class='alert alert-success'>Packet Now Marked as Picked Up</h3>"

Process()

Explanation of code

The entire script consists of the definition of a function called Process() followed by a call to that function. The reason a function is defined, is to make it easy to return from the script at various points in the process. This also keeps from having to nest the code in more if statements.

Line 2

This line checks to see if there is a barcode that has been entered or scanned and returns without doing anything if there is no barcode.

Lines 5-7

Decomposes the barcode into the two constituant parts, orgid and peopleid.

Lines 9-14

Gets the person, spouse and class (the organization) for the registrant using built in functions available to TouchPoint’s Python scripts. The InOrg function returns true or false whether a person is a member of the org or not.

Lines 16-23

Display various warning messages for missing or incorrect data.

Line 25

Begins the rest of the process if the person and org exist.

Line 26-41

Displays a table with information about the registration. Line 34 returns if the person is not a member of the org.

Lines 43-55

Adds or removes a person from the “pay online” sub-group based on the first two radio buttons checked.

The default Paid option button is “no change” (line 49) and will display the paid status for the user.

Lines 57-59

If the radio button for “Mark Not Picked up” is checked, then the person is removed from the “packet-pickedup” sub-group.

Lines 60-67

The default for this radio button group (“Picked up”) is to mark the person has having picked up their packet. The if, elif, and else statements will indicate whether the Packet has already been picked up, or whether the Packet has not been successfully marked as picked up.

Line 69

Finally, the actual work does not happen until the Process() function, just defined, is called.

The FPUPacket.js file will post the form to the script and the script FPUPacketProcess.py will be called.

$.post("/PyScriptForm/", q, function (ret) {
    $("#output").html(ret);
    $("#wandtarget").focus();
});