Пример #1
0
 def subject_init(row):
     subject = Subject()
     num = Subject.query.filter_by(name=row['Nom']).count()
     if num > 0:
         Subject.query.delete()
     study = Study.query.filter_by(name=row['Etude']).first()
     subject.name = row['Nom']
     subject.description = row['Description']
     subject.study = study
     return subject
Пример #2
0
def init_subjects():
    for sg in list(C_SubjectGroup):
        saved_subject_group = SubjectGroup.query.filter_by(type=sg.name).first()
        if saved_subject_group is None:
            add_subject_group = SubjectGroup()
            add_subject_group.type = sg.name
            add_subject_group.name = sg.value
            db.session.add(add_subject_group)
            db.session.flush()
            saved_subject_group = add_subject_group
        for subj in C_SubjectGroup.get_subjects(saved_subject_group.type):
            saved_subject = Subject.query.filter_by(type=subj.name).first()
            if saved_subject is None:
                add_subject = Subject()
                add_subject.type = subj.name
                add_subject.name = subj.value
                add_subject.subject_group_id = saved_subject_group.id
                db.session.add(add_subject)
    db.session.commit()