How can you determine the methods and attributes of objects in PloneFormGen? I want to write some scripts for a custom field adapter and would like to know what is available. My immediate problem comes from some online code I copied from: Python script to hide ploneformgen form after user has filled it out. (For Plone-4.3.2-64.)
alreadyInDB = False
savedData = ploneformgen.savefield.getSavedFormInputForEdit()
username = request.AUTHENTICATED_USER.getId()
return {'username': 'No way man!'}
usersInDB = [x.split(',')[1] for x in savedData.split('\r\n') if len(x)>0]
if username in usersInDB:
alreadyInDB = True
if alreadyInDB:
return {'username': 'No way man!'}
This is the error message I get.
AttributeError: savefield
What I want to do is see what is available for attributes and methods and either fix this or write my own. Any help is appreciated.
This is what we use: PloneFormGen 1.7.12 Products.PFGExtendedMailAdapter 2.4
Plone 4.3.3 (4308) CMF 2.2.7 Zope 2.13.22 Python 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] PIL 2.0.0 (Pillow)
Call
dir()on an object to return a list of all available methods and attributes it has.Alternatively, use
inspect.getsource()on a function, class, class method or class attribute to return the source code associated with it.Example using a pandas DataFrame object:
Note that
getsourceneeds to access the attribute/method of the actual class (in this casepd.DataFrame) instead of an instance of that class (dfin this example). So you can usedirfirst to figure out the methods/attributes, andgetsourceon a specific method/attribute afterwards to see the code.