Пример #1
0
def db_load_default_questionnaires(session):
    qfiles = [os.path.join(Settings.questionnaires_path, path) for path in os.listdir(Settings.questionnaires_path)]
    questionnaires = []
    qids = []

    for qfile in qfiles:
        questionnaires.append(read_json_file(qfile))
        qids.append(questionnaires[-1]['id'])

    session.query(models.Questionnaire).filter(models.Questionnaire.id.in_(qids)).delete(synchronize_session='fetch')
    session.query(models.Step).filter(models.Step.questionnaire_id.in_(qids)).delete(synchronize_session='fetch')

    for questionnaire in questionnaires:
        db_create_questionnaire(session, 1, questionnaire, None)
Пример #2
0
def load_default_questionnaires(session):
    qfiles = [os.path.join(Settings.questionnaires_path, path) for path in os.listdir(Settings.questionnaires_path)]
    questionnaires = []
    qids = []

    for qfile in qfiles:
        questionnaires.append(read_json_file(qfile))
        qids.append(questionnaires[-1]['id'])

    session.query(models.Questionnaire).filter(models.Questionnaire.id.in_(qids)).delete(synchronize_session='fetch')
    session.query(models.Step).filter(models.Step.questionnaire_id.in_(qids)).delete(synchronize_session='fetch')

    for questionnaire in questionnaires:
        db_create_questionnaire(session, State, 1, questionnaire, None)
Пример #3
0
def db_load_default_questionnaires(session):
    """
    Transaction for loading default questionnaires
    :param session: An ORM session
    """
    qfiles = [
        os.path.join(Settings.questionnaires_path, path)
        for path in os.listdir(Settings.questionnaires_path)
    ]
    questionnaires = []
    qids = []

    for qfile in qfiles:
        questionnaires.append(read_json_file(qfile))
        qids.append(questionnaires[-1]['id'])

    db_del(session, models.Questionnaire, models.Questionnaire.id.in_(qids))
    db_del(session, models.Step, models.Step.questionnaire_id.in_(qids))

    for questionnaire in questionnaires:
        db_create_questionnaire(session, 1, questionnaire, None)