def create_pdf(): ## Normally you would have a PDF on the local disk, in which case you would ## do something like this: #pdf = BibItem.encode_pdffile('/path/to/my/cool.pdf', 'Testdata') ## or: #pdf = BibItem.encode_pdf('my.pdf', open('/path/to/my/cool.pdf').read()) ## But for this example, we just use a simple string pdf = BibItem.encode_pdf('my.pdf', 'Testdata') return pdf
def portal_state_updatedmessage(update_response): print 'Updated', update_response['attributes']['id'] print 'The current portal_state is "{portal_state}", and the next possible states are: '.format(**update_response) pprint(update_response['portal_state_transitions']) ## Setup our login credentials. auth = dict(username='******', password='******') folder = BibFolder(decode_output=True, **auth) exampleitemid = auth['username'] + '-pubexample' ## Create the item (it will be private by default) pdf = BibItem.encode_pdf('my.pdf', 'Testdata') create_response = folder.create_item(exampleitemid, 'ArticleReference', attributes={'title': 'Example', 'publication_year': '2012', 'authors': [{'firstnames': 'Hans Petter', 'lastname': 'Langtangen', 'username': '******'}, {'username': '******', 'firstnames': 'Carsten', 'lastname': 'Griwodz'}], 'simula_pdf_file': pdf}) print 'Created {title}'.format(**create_response['attributes']) print ' View it here: {url}'.format(**create_response) print 'The current portal_state is "{portal_state}", and the next possible states are: '.format(**create_response) pprint(create_response['portal_state_transitions'])