Beispiel #1
0
def library_to_dict(library,db_session):
    result =[]
    for item in library:
        lib_item = model_basic_dict(item)
        lib_attrs = {'status':item.status,
                     'book':book_to_dict(db_session,item.book)
                     }
        lib_item.update(lib_attrs)
        result.append(lib_item)
    return result
def lib_to_dict(item, db_session):
    res = model_basic_dict(item)
    item_dict = {
        'book_id': item.book_id,
        'person_id': item.person_id,
        'status': item.status,
        'progress': item.progress,
        'book': book_to_dict(db_session, item.book)
    }
    item_dict.update(res)
    return item_dict
def lib_to_dictlist(library, db_session):
    result = []
    for item in library:
        res = model_basic_dict(item)
        item_dict = {
            'book_id': item.book_id,
            'person_id': item.person_id,
            'status': item.status,
            'progress': item.progress,
            'book': book_to_dict(db_session, item.book)
        }
        item_dict.update(res)
        result.append(item_dict)
    return result
Beispiel #4
0
def content_to_dict(content, db_session):
    result = model_to_dict(content)
    attrs = {
        'book_id': content.book_id,
        'content': content.content,
        'book_press': content.book_press,
        'book': book_to_dict(db_session, content.book)
    }
    if isinstance(content.type, str):
        attrs.update({'type': content.type})
    else:
        attrs.update({'type': content.type.value})
    result.update(attrs)
    return result
Beispiel #5
0
def collection_to_dict(db_session, collection):
    if not isinstance(collection, Collection):
        raise Http_error(400, Message.INVALID_ENTITY)
    basic_res = model_basic_dict(collection)
    model_props = {
        'book_id': collection.book_id,
        'person_id': collection.person_id,
        'title': collection.title,
        'book': None
    }
    if collection.book_id is not None:
        book = book_to_dict(db_session, collection.book)
        model_props['book'] = book
        model_props.update(basic_res)

        logger.debug('*****coll is  model_props: %s', model_props)
    return model_props