We can access fleshed fields if we use the field name, not the class hint
authordbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 22 Mar 2011 20:33:04 +0000 (20:33 +0000)
committerdbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 22 Mar 2011 20:33:04 +0000 (20:33 +0000)
D'oh! Bill pointed this brain damage out to me, too.

Also, clean up the output somewhat and move the authentication
near to the end so that at least some of the methods can be
invoked.

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1276 6d9bc8c9-1ec2-4278-b937-99fde70a366f

tools/python-sample/osrf_gateway_request.py

index 257263f..ef20d1a 100644 (file)
@@ -10,6 +10,7 @@ import oils.utils.idl
 import oils.utils.utils
 import osrf.gateway
 import osrf.json
+import sys
 import tempfile
 import urllib2
 
@@ -55,8 +56,6 @@ def login(username, password, workstation=None):
 
     __authtoken = None
 
-    print("attempting login with user " + username)
-
     seed = request(
         'open-ils.auth', 
         'open-ils.auth.authenticate.init', username).send()
@@ -66,8 +65,8 @@ def login(username, password, workstation=None):
 
     result = request(
         'open-ils.auth',
-        'open-ils.auth.authenticate.complete',
-        {   'workstation' : workstation,
+        'open-ils.auth.authenticate.complete', {
+            'workstation' : workstation,
             'username' : username,
             'password' : password,
             'type' : 'staff' 
@@ -120,50 +119,50 @@ if __name__ == '__main__':
     # Pull all of our object definitions together
     load_idl()
 
-    # Log in and get an authtoken
-    authtoken = login('foo', 'bar')
-
-    # Issue a plain old position-dependent request
+    print("Issue a plain old position-dependent request:")
     req = request('open-ils.search', 'open-ils.search.biblio.record.copy_count', 105, 891001, None)
     res = req.send()
-    print(res[0])
+    print("\t%s\n" % res[0])
 
-    # Get a plain Jane acp (copy) object by barcode
+    print("Get a plain Jane acp (copy) object by barcode:")
     barcode = '791068-1001'
     req = request('open-ils.search', 'open-ils.search.asset.copy.find_by_barcode', barcode)
     barcode_copy = req.send()
-    print "Raw JSON: ", osrf.json.to_json(barcode_copy)
+    print("\tRaw JSON: %s" % osrf.json.to_json(barcode_copy))
 
     # id() and call_number() are fields defined in fm_IDL.xml
-    print "Copy ID: ", barcode_copy.id()
-    print "Call number ID: ", barcode_copy.call_number()
+    print("\tCopy ID: %s" % barcode_copy.id())
+    print("\tCall number ID: %s\n" % barcode_copy.call_number())
 
-    # Get a fleshed out copy (now with more fields!) by barcode
+    print("Get a fleshed out copy (now with more fields!) by barcode:")
     req = request('open-ils.search', 'open-ils.search.asset.copy.fleshed2.find_by_barcode', barcode)
     barcode_copy = req.send()
-    print "Raw JSON: ", osrf.json.to_json(barcode_copy)
+    print("\tRaw JSON: %s" % osrf.json.to_json(barcode_copy))
 
     # id() and call_number() are fields defined in fm_IDL.xml
-    print "Copy ID: ", barcode_copy.id()
-    print "Call number ID: ", barcode_copy.call_number()
-
-    # Note - fleshed fields don't appear to be retrievable with the expected syntax
-    # The following does _not_ work:
-    #
-    # print "Copy location: ", barcode_copy.acpl().name()
-    #
-    # And the following just prints null values for an acpl object:
-    #
-    # print osrf.json.to_json(barcode_copy.acpl())
-
-    # Get a plain acn (callnumber) object by ID
+    print("\tCopy ID: %s" % barcode_copy.id())
+    print("\tCall number ID: %s" % barcode_copy.call_number())
+
+    # Get one of the fleshed fields
+    print("\tCopy location: %s\n" % barcode_copy.location().name())
+
+    print("Get a plain acn (callnumber) object by ID:")
     req = request('open-ils.search', 'open-ils.search.asset.call_number.retrieve', barcode_copy.call_number())
     call_num = req.send()
-    print "Raw JSON: ", osrf.json.to_json(call_num)
-    print "Call number ID: ", call_num.id()
-    print "Call number label: ", call_num.label()
+    print("\tRaw JSON: %s" % osrf.json.to_json(call_num))
+    print("\tCall number ID: %s" % call_num.id())
+    print("\tCall number label: %s\n" % call_num.label())
+
+    authtoken = ''
+
+    try:
+        # Log in and get an authtoken
+        authtoken = login('foo', 'bar')
+    except AuthException, exc:
+        print("Failed logging in: %s" % str(exc))
+        sys.exit(1)
 
-    # Change the call number and update it
+    print("Change the call number and update it:")
     call_num.label('FOOTWICH')
     call_num.ischanged(True)