itemid = create_response['attributes']['id']
exampleitem = BibItem(itemid, decode_output=True, **auth)


# Pretend to update (no changes are stored in the database, but the response is just like it would be on a regular update)
update_attributes = {'title': 'Updated example item using the Python REST client library'}
pretend_update_response = exampleitem.update(portal_type,
                                             attributes=update_attributes,
                                             pretend=True)
print 'Updated using pretend=True. This does not change the database, as you can see by doing a GET-request:'
get_response = exampleitem.get()
print '    Title stored in the database: ', get_response['attributes']['title']
#pprint(pretend_update_response) # Pretty-print the entire response


# Show the user a DIFF between the pretend_update_response and get_response, and ask them to confirm the changes
print 'Are you sure you want to make the following changes to {id}:'.format(**get_response['attributes'])
print create_diff(get_response['attributes'], pretend_update_response['attributes'])
if raw_input('Confirm changes (y|N): ') == 'y':
    # Really update the item (with pretend=False)
    update_response = exampleitem.update(portal_type,
                                         attributes=update_attributes)
    print 'Updated {id}'.format(**update_response['attributes'])
else:
    print 'Update aborted by user'


# Open a browser "confirm delete" view to delete the item we created
print 'Opening {delete_url} in your browser...'.format(delete_url=exampleitem.get_browser_deleteurl())
exampleitem.browser_confirm_delete()
Exemplo n.º 2
0
          'attributes': {'id': 'grandma-example',
                   'title': 'Super bulk updated example'}}]


# Lets start with getting the current values for our items,
# just to have values to compare with when asking the 
# user to confirm the changes (below)
itemids = [item['attributes']['id'] for item in items]
current_values = folder.search(itemids=itemids)
#pprint(current_values) # pretty-print response


# Then pretend to update to get the changes that will be applied when we update
# for real
pretend_response = folder.bulk_update(pretend=True,
                                      items=items)
#pprint(pretend_response) # pretty-print response


# Ask the user to confirm before bulk updating
print 'Are you sure you want to make the following changes:'
print create_diff(current_values['items'], pretend_response['items'])
if raw_input('Confirm changes (y|N): ') == 'y':
    response = folder.bulk_update(items=items)

    # List the changed items
    print 'Changed items:'
    for item in response['items']:
        print '-', item['url']
    #pprint(response) # pretty-print reponse