Exemplo n.º 1
0
def restore_structure_of_db():
    full_backup_to_restore = Template.find_by_name(
        'full_Ewa').json_template['instances']
    Activity.delete_all_objects_by_current_user()
    Category.delete_all_objects_by_current_user()
    for single_record in full_backup_to_restore:
        if not Category.find_by_name(single_record['category']):
            new_category = Category(category=single_record['category'],
                                    username_id=current_user.id)
            db.session.add(new_category)
            db.session.commit()
        new_activity = Activity(name=single_record['activity'],
                                category_id=Category.find_by_name(
                                    single_record['category']).id,
                                username_id=current_user.id)
        db.session.add(new_activity)
        db.session.commit()
    return redirect(url_for('backup_structure_of_db'))