Checking Active User (Python)

Checking Active User (Python)
 1ot = impact.gui.output_toolbox
 2db = impact.active_database
 3
 4def DisplayActiveUser(doc):
 5    if doc.is_checked_out:
 6        ot.add("Current Active User: " + doc.active_user.login_id)
 7        activeDoc = doc.active_checkout
 8
 9        ot.add("  Checked out: " + str(activeDoc.modified_date_time))
10    else:
11        ot.add("No Active User")
12cust = db.customers.find_by_code("ACME CORP")
13
14if not cust.isNone():
15    docs = cust.documents
16
17    if docs.isNone():
18        ot.add("No customer document support in the database")
19    else:
20        ot.add("customer document support is enabled in this database")
21        doc = None
22        try:
23            doc = docs.item("Acme Corporation Specifications.docx")
24        except Exception as exc:
25            pass
26        impact.gui.output_toolbox.add(f"Failed to create object via docs.item(): {exc}")
27
28        if not doc.isNone():
29            ot.add("Document: '" + doc.name + "', impact.creator: " + doc.added_by.login_id + ", Size: " + doc.size + " bytes")
30
31            DisplayActiveUser(doc)
32
33            ot.add("Checking out document for modification")
34
35            if doc.checkout():
36
37                DisplayActiveUser(doc)
38
39                ot.add("Cancelling checkout")
40
41                if doc.active_checkout.cancel_checkout():
42
43                    DisplayActiveUser(doc)
44
45                else:
46
47                    ot.add("Unable to cancel checkout")
48
49            else:
50
51                ot.add("Unable to checkout document")
52
53            for item in doc.history:
54                ot.add("  Operation: " + item.operation_as_string + " by " + item.modified_by.login_id + " at " + str(item.modified_date_time))
55                if Len(item.details) > 0:
56                    ot.add("    " + item.details)
57        else:
58            ot.add("Unable to locate document")
59
60else:
61    ot.add("Unable to locate a customer")
62
63ot.clear()