Quantcast
Channel: DreamFactory Forum - Latest posts
Viewing all articles
Browse latest Browse all 5027

Python scripting questions

$
0
0

In 2.1.2 event and platform are both Python dictionary type. You need to use them as regular dictionary. So, organization_id is not going to exist in payload but will exist in payload['resource']. In the up coming release of DF2, event and platform will be Python bunch type. This will allow easy access to values using dot (.) notation like in JavaScript. You will be able to do the following

verb = event.request.method; # always returns POST in this example
payload = event.request.payload;
records = payload.resource;  #all records in the post
record = records[0];  # first record

Directly accessing a key that doesn't exist from Python dictionary will throw error, therefore, you need to check the key before accessing it. Unfortunately there isn't a better way to do this currently or at least I don't know of one. You could do this in one line like below which is a bit shorter but not really a better way.

lastname = record['last name'] if('lastname' in record) else '';

All values coming from PHP side are going to be string.


Viewing all articles
Browse latest Browse all 5027

Trending Articles