Example #1
0
def upload_new(**kwargs):
    from RESTClient import MozuRestClient
    from db import mozu_image_table_instance

    mzclient = MozuRestClient(**kwargs)
    mz_imageid, document_resource = mzclient.create_new_mz_image()
    print mz_imageid, document_resource, ' <-- MozuID -- Docresource'
    if document_resource == "Keyerror":
        print mz_imageid, ' <-- MozuID'
    elif document_resource == "documentTree":
        bf_imageid = mzclient.bf_imageid
        kwargs['bf_imageid'] = bf_imageid
    elif document_resource == "documentListDocumentContent":
        kwargs['mz_imageid'] = mz_imageid
    mozu_image_table = mozu_image_table_instance()
    table_args = include_keys(kwargs, __mozu_image_table_valid_keys__)
    insert_db = mozu_image_table.insert(values=dict(**table_args))
    print "Inserting with, ", insert_db
    if kwargs['bf_imageid']:
        content_response = update_content_mz_image(**kwargs)
        try:
            insert_db.execute()
            print 'Inserted --> ', kwargs.items(), ' <-- ', insert_db
        except sqlalchemy.exc.IntegrityError:
            update_db = mozu_image_table.update(values=dict(**table_args),whereclause=mozu_image_table.c.bf_imageid == table_args['bf_imageid'])
            print 'Updating after IntegrityERR with args--> ', kwargs     # # Insert to mz_imageid + **kwargs to Oracle
            update_db.execute()
        return content_response