def migrate_datas():
    logger = logging.getLogger("alembic.autonomie")
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()
    from autonomie.models.config import Config
    import json

    from autonomie.models.files import (
        File,
        FileType,
    )
    json_str = Config.get_value("attached_filetypes", "[]")
    try:
        configured_filetypes = json.loads(json_str)
    except:
        logger.exception(u"Error in json str : %s" % json_str)
        configured_filetypes = []
    if configured_filetypes:
        result = []
        for filetype_label in configured_filetypes:
            if filetype_label:
                filetype = FileType(label=filetype_label)
                session.add(filetype)
                session.flush()
                result.append(filetype)

        for typ_ in result:
            query = File.query().filter_by(label=typ_.label)
            for file_ in query:
                file_.file_type_id = typ_.id
                session.merge(file_)
        session.flush()
Exemplo n.º 2
0
def _add_filetype_and_reqs(session, business_type_label, filetype,
                           requirements):
    """
    """
    from autonomie.models.files import FileType
    from autonomie.models.project.types import BusinessType
    from autonomie.models.project.file_types import BusinessTypeFileType
    if session.query(FileType.id).filter_by(label=filetype).count() == 0:
        f = FileType(label=filetype)
        session.add(f)
        session.flush()
        btype_id = session.query(
            BusinessType.id).filter_by(name=business_type_label).scalar()

        for req_dict in requirements:
            req = BusinessTypeFileType(file_type_id=f.id,
                                       business_type_id=btype_id,
                                       doctype=req_dict['doctype'],
                                       requirement_type=req_dict['req_type'],
                                       validation=req_dict.get(
                                           'validation', False))
            session.add(req)
        session.flush()
Exemplo n.º 3
0
def file_type(dbsession):
    from autonomie.models.files import FileType
    f = FileType(label=u"Label")
    dbsession.add(f)
    dbsession.flush()
    return f
Exemplo n.º 4
0
 def func(label):
     model = FileType(label=label)
     dbsession.add(model)
     dbsession.flush()
     return model