'publication_year': '2012'})
print 'Created {title}'.format(**create_response['attributes'])
print '   View it here: {url}'.format(**create_response)
#pprint(create_response) # Pretty-print the entire response



# Get the created bibitem
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'])
Ejemplo n.º 2
0
# Work with the item API
# - Get all attributes of a single item, including the PDF data
# - Update attributes of an item
# - Delete single item via the web-browser
###############################################

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

get_response = exampleitem.get(include_filefields=True)
print 'Got:', get_response['url']
print '   url:', get_response['url']
print '   portal_type:', get_response['portal_type']
print '   title:', get_response['attributes']['title']
print '   simula_pdf_file:', get_response['attributes']['simula_pdf_file']
print '   simula_pdf_file decoded:', BibItem.decode_pdf(get_response['attributes']['simula_pdf_file'])
#pprint(get_response) # Pretty-print the entire response


portal_type = get_response['portal_type']
update_response = exampleitem.update(portal_type,
                                     attributes={'title': 'Updated example item using the Python REST client library'})
print 'Updated', update_response['attributes']['id']
print '   new title:', update_response['attributes']['title']
#pprint(update_response) # Pretty-print the entire response


# 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()