def paste_cell_handler(message, resource): target_nb = get_notebook(message['target']) addresses = message['addresses'] addresses.reverse() labels = message['labels'] labels.reverse() new_cells = [] for address in addresses: source = address.split('#')[0] cell = address.split('#')[1] new_cells.append(insert_cell(target_nb, source, cell)) write_notebook(message['target'], target_nb, resource.notebook_item_order) return simplejson.dumps({'target' : message['target'], 'id' : message['id'], 'links' : zip(labels, new_cells)})
def insert_new_entry(fn, entry, resource): try: data = get_notebook(fn) bibliography = data.get('bibliography') except EnvironmentError: return 'Could not write file %s'%(fn) if bibliography: keys = bibliography.keys() keys.sort(key=int) new_key = int(keys[-1]) + 1 if entry: bibliography['%s'%new_key] = entry data['date'] = datetime.datetime.now().strftime(resource.time_format) data['bibliography'] = bibliography return write_notebook(fn, data, resource.bibliography_item_order)