def update_edition(key, old, new): print 'key:', key print 'old:', old print 'new:', new e = ol.get(key) fix_edition(key, e, ol) authors = [] print 'current authors:', e['authors'] for cur in e['authors']: cur = cur['key'] print old, cur in old a = new if cur in old else cur print cur, '->', a if a not in authors: authors.append({'key': a}) print 'authors:', authors e['authors'] = authors try: print ol.save(key, e, 'merge authors') except: print e raise new_edition = ol.get(key) if 'table_of_contents' in new_edition: # [{u'type': <ref: u'/type/toc_item'>}, ...] print key, new_edition['table_of_contents']
def run_queue(queue): work_keys = add_works(queue) for w, wkey in zip(queue, work_keys): w['key'] = wkey write_log('work', wkey, w['title']) for ekey in w['editions']: e = ol.get(ekey) fix_edition(ekey, e, ol) #assert 'works' not in e write_log('edition', ekey, e.get('title', 'title missing')) e['works'] = [Reference(w['key'])] yield e
def update_edition(ekey, wkey): e = ol.get(ekey) fix_edition(ekey, e, ol) write_log('edition', ekey, e.get('title', 'title missing')) if e.get('works', []): assert len(e['works']) == 1 if e['works'][0] != wkey: print('e:', e) print('wkey:', wkey) print('ekey:', ekey) print('e["works"]:', e['works']) #merge_works([e['works'][0], wkey]) #assert e['works'][0] == wkey return None e['works'] = [Reference(wkey)] return e
def update_edition(ol, e, old, new, debug=False): key = e['key'] if debug: print('key:', key) print('old:', old) print('new:', new) fix_edition(key, e, ol) authors = [] if debug: print('current authors:', e['authors']) for cur in e['authors']: cur = cur['key'] if debug: print(old, cur in old) a = new if cur in old else cur if debug: print(cur, '->', a) if a not in authors: authors.append(a) if debug: print('authors:', authors) e['authors'] = [{'key': a} for a in authors] try: ret = ol.save(key, e, 'merge authors') except: if debug: print(e) raise if debug: print(ret) update = [] for wkey in e.get('works', []): need_update = False print('work:', wkey) w = ol.get(wkey) for a in w['authors']: if a['author'] in old: a['author'] = Reference(new) need_update = True if need_update: update.append(w) if update: ret = ol.save_many(update, 'merge authors')
def update_edition(ol, e, old, new, debug=False): key = e['key'] if debug: print 'key:', key print 'old:', old print 'new:', new fix_edition(key, e, ol) authors = [] if debug: print 'current authors:', e['authors'] for cur in e['authors']: cur = cur['key'] if debug: print old, cur in old a = new if cur in old else cur if debug: print cur, '->', a if a not in authors: authors.append(a) if debug: print 'authors:', authors e['authors'] = [{'key': a} for a in authors] try: ret = ol.save(key, e, 'merge authors') except: if debug: print e raise if debug: print ret update = [] for wkey in e.get('works', []): need_update = False print 'work:', wkey w = ol.get(wkey) for a in w['authors']: if a['author'] in old: a['author'] = Reference(new) need_update = True if need_update: update.append(w) if update: ret = ol.save_many(update, 'merge authors')
def add_work(akey, w): q = { 'authors': [{'author': Reference(akey)}], 'type': '/type/work', 'title': w['title'] } try: wkey = ol.new(q, comment='create work page') except: print q raise write_log('work', wkey, w['title']) assert isinstance(wkey, basestring) for ekey in w['editions']: e = ol.get(ekey) fix_edition(ekey, e, ol) #assert 'works' not in e write_log('edition', ekey, e.get('title', 'title missing')) e['works'] = [Reference(wkey)] yield e
def add_work(akey, w): q = { 'authors': [{ 'author': Reference(akey) }], 'type': '/type/work', 'title': w['title'] } try: wkey = ol.new(q, comment='create work page') except: print(q) raise write_log('work', wkey, w['title']) assert isinstance(wkey, six.string_types) for ekey in w['editions']: e = ol.get(ekey) fix_edition(ekey, e, ol) #assert 'works' not in e write_log('edition', ekey, e.get('title', 'title missing')) e['works'] = [Reference(wkey)] yield e