Beispiel #1
0
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')
Beispiel #2
0
def add_works(akey, works):
    queue = []
    for w in works:
        w['key'] = next_work_key()
        q = {
            'authors': [akey],
            'create': 'unless_exists',
            'type': '/type/work',
            'key': w['key'],
            'title': w['title']
        }
        #queue.append(q)
        print(ol.write(q, comment='create work'))
        for ekey in w['editions']:
            e = ol.get(ekey)
            fix_edition(ekey, e, ol)
            e['works'] = [Reference(w['key'])]
            try:
                ol.save(ekey, e, 'found a work')
            except olapi.OLError:
                print(ekey)
                print(e)
                raise
Beispiel #3
0
def toc_items(toc_list):
    return [{
        'title': six.text_type(item),
        'type': Reference('/type/toc_item')
    } for item in toc_list]
Beispiel #4
0
def toc_items(toc_list):
    return [{
        'title': unicode(item),
        'type': Reference('/type/toc_item')
    } for item in toc_list]