示例#1
0
文件: logic.py 项目: kennydo/medea
def create_work(work_dict):
    work_dict = dict(work_dict)
    work_dict.pop('id', None)
    with session_scope() as session:
        roles = work_dict.pop('roles', None)
        tags = work_dict.pop('tags', None)
        new_work = Work(**work_dict)
        session.add(new_work)
        if roles:
            _update_roles_for_work(session, roles, new_work)
        if tags:
            #TODO: Add tags
            pass
        session.commit()
        return new_work.to_dict()
示例#2
0
def create_fake_work(
    type=None,
    title=None,
    catalog_number=None,
    release_date=None,
    description=None,
    is_active=True,
):
    work_dict = {
        'type': type or random_word_generator(), # Change this if types become enums
        'title': title or random_word_generator(2),
        'catalog_number': catalog_number or 'CAT-{0}'.format(random.randint(10000,99999)),
        'release_date': release_date or datetime.datetime.today(),
        'description': description or random_word_generator(15),
        'is_active': is_active
    }
    with session_scope() as session:
        new_fake_work = Work(**work_dict)
        session.add(new_fake_work)
        session.commit()
        work_dict = api_to_model_dict({'work': new_fake_work.to_dict()})
        return work_dict