def create_new_course(): session = Session() # Check if the user is logged in if 'username' not in login_session: return redirect('/login') if request.method == 'GET': # Get all programs programs = session.query(Programs).all() return render_template('create_new_course.html', programs=programs) else: # Check if the form was correctly filled in if not request.form['title']: flash('Enter the course title please!') return redirect(url_for('create_new_course')) if not request.form['program_id']: flash('Select the program of the course please!') return redirect(url_for('create_new_course')) # Add course new_course = Courses( title=request.form['title'], description=request.form['description'], program_id=request.form['program_id'], user_id=login_session['user_id']) session.add(new_course) session.commit() # Display the program courses of the new course program = session.query(Programs).filter_by( id=request.form['program_id']).first() Session.remove() return redirect(url_for('display_program_courses', program_title=program.title))
def new_course(category_id): if request.method == 'POST': new_course = Courses(name=request.form['name'], description=request.form[ 'description'], link=request.form['link'],photo_url=request.form['photo_url'], category_id=category_id) session.add(new_course) session.commit() return redirect(url_for('show_courses', category_id=category_id)) else: return render_template('new_course.html', category_id=category_id)
def new_course(category_id): # Get fnction for create courses if 'username' not in login_session: return redirect('/login') if request.method == 'POST': new_course = Courses(name=request.form['name'], description=request.form['description'], link=request.form['link'], photo_url=request.form['photo_url'], category_id=category_id) session.add(new_course) session.commit() flash('course Successfully created %s' % new_course.name) return redirect(url_for('show_courses', category_id=category_id)) else: return render_template('new_course.html', category_id=category_id)
# database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Menu for UrbanBurger category1 = Categories(name="Urban Burger") session.add(category1) session.commit() Courses2 = Courses(name="Veggie Burger", description="Juicy grilluce", link="$7.50", photo_url="Entree", category=category1) session.add(Courses2) session.commit() Courses1 = Courses(name="French Fries", description="with garrmesan", link="$2.99", photo_url="Appetizer", category=category1) session.add(Courses1) session.commit() Courses2 = Courses(name="Chicken Burger",
program5 = Programs(title='Autonomous Systems') session.add(program5) session.commit() program6 = Programs(title='Business') session.add(program6) session.commit() # Inserting some courses in each program # The user_id is by default 1 course = Courses( title='Machine Learning Engineer', description='''Learn advanced machine learning algorithms and how to deploy your models to a production environment. Gain practical experience using Amazon SageMaker to deploy trained models to a web application and evaluate its performance. AB test models and learn how to update the models as you gather more data.''', programs=program1, ) session.add(course) session.commit() course = Courses( title='Deep Learning', description='''Deep learning is driving advances in artificial intelligence that are changing our world. Enroll now to build and apply your own deep neural networks to challenges like image classification and generation, time-series prediction, and model deployment.''', programs=program1,
# and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Menu for UrbanBurger category1 = Categories(name="Urban Burger") session.add(category1) session.commit() Courses2 = Courses(name="Veggie Burger", description="Juicy grilled veggie patty with tomato mayo and lettuce", link="$7.50", photo_url="Entree", category=category1) session.add(Courses2) session.commit() Courses1 = Courses(name="French Fries", description="with garlic and parmesan", link="$2.99", photo_url="Appetizer", category=category1) session.add(Courses1) session.commit() Courses2 = Courses(name="Chicken Burger", description="Juicy grilled chicken patty with tomato mayo and lettuce", link="$5.50", photo_url="Entree", category=category1) session.add(Courses2)