def update_course(id): course = Course.query.get_or_404(id) enrolments = Enrolment.find_enrolments_by_course(id) nr_of_enrolments_on_course = len(enrolments) if request.method == 'POST': form = CourseForm(request.form) if not form.validate(): return render_template('courses/update.html', course=course, form=CourseForm(name=course.name, description=course.description, max_participants=course.max_participants )) #updatessa määriteltävä max osallistujamäärä < jo ilmoittautuneet: if (form.max_participants.data < nr_of_enrolments_on_course): error = 'Kurssille ' + course.name + ' on ilmoittautunut jo ' + str(nr_of_enrolments_on_course) + ' koiraa. Et voi päivittää osallistujamäärää pienemmäksi kuin ' + str(nr_of_enrolments_on_course) + '.' return render_template('/courses/update_error.html', error=error) course.name = form.name.data course.description = form.description.data course.max_participants = form.max_participants.data db.session.commit() return redirect('/courses') else: return render_template('courses/update.html', course=course, form=CourseForm(name=course.name, description=course.description, max_participants=course.max_participants ))
def courses_modify(course_id): c = Course.query.get(course_id) form = CourseForm(request.form) if not form.validate(): return render_template( "courses/edit.html", form=form, course=c, courseStart=(str(c.startingDate.year) + "-" + str(c.startingDate.month) + "-" + str(c.startingDate.day)), courseEnd=(str(c.endingDate.year) + "-" + str(c.endingDate.month) + "-" + str(c.endingDate.day))) c.name = form.name.data c.location = form.location.data c.startingDate = form.startingDate.data c.endingDate = form.endingDate.data c.description = form.description.data c.price = form.price.data db.session().add(c) db.session().commit() return redirect(url_for("courses_index"))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form=form) c = Course(form.nimi.data) db.session().add(c) db.session().commit() return redirect(url_for("courses_index"))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form=form) c = Course(form.name.data, form.description.data, form.max_participants.data) db.session().add(c) db.session().commit() return redirect(url_for("courses_index"))
def courses_edit(course_id): c = Course.query.get(course_id) form = CourseForm(request.form) if not form.validate(): return render_template("courses/edit.html", form=form) c.name = form.name.data c.description = form.description.data db.session().commit() return redirect(url_for("courses_index"))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form=form) c = Course(form.name.data, form.description.data) c.account_id = current_user.id db.session().add(c) db.session().commit() return redirect(url_for("courses_index"))
def edit_course(course_id): courseToEdit = Course.query.get_or_404(course_id) form = CourseForm(formdata=request.form, obj=courseToEdit) if form.validate(): courseToEdit.name = form.name.data courseToEdit.description = form.description.data db.session().commit() return redirect(url_for("courses_index")) else: return render_template("courses/edit_course.html", form=form)
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form=form) course = Course(form.name.data, form.datestart.data, form.dateend.data, form.place.data, form.teachers.data, form.desc.data, form.topic.data) db.session().add(course) db.session().commit() return redirect(url_for("courses_index"))
def courses_update(course_id): form = CourseForm(request.form) course = Course.query.get(course_id) if not form.validate(): return render_template("/courses/edit.html", course=course, form=form) course.course_id = form.course_id.data course.title = form.title.data course.description = form.description.data course.duration = form.duration.data course.deadline = form.deadline.data db.session().commit() return redirect(url_for("courses_course", course_id=course_id))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("/courses/new.html", form=form) c = Course(form.course_id.data, form.title.data, form.description.data, form.duration.data, form.deadline.data) u = User.query.get(current_user.id) c.users.append(u) db.session().add(c) db.session().commit() return redirect(url_for("courses_mycourses"))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form=form) t = Course(form.name.data) m = Course.query.filter(Course.name == form.name.data).count() if m > 0: return redirect(url_for("course_index")) else: db.session().add(t) db.session().commit() return redirect(url_for("courses_form"))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form=form) t = Course(form.name.data, form.location.data, form.startingDate.data, form.endingDate.data, form.description.data, form.price.data, form.organizerIban.data) if current_user.iban == "": current_user.iban = form.organizerIban.data t.account_id = current_user.id db.session().add(t) db.session().commit() return redirect(url_for("courses_index"))
def courses_create(): form = CourseForm(request.form) if not form.validate(): return render_template("courses/new.html", form = form) courseExists = Course.query.filter_by(name=form.name.data).first() if courseExists: return render_template("courses/new.html", form = form, error = "Course already exists") courseCodeExists = Course.query.filter_by(coursecode=form.coursecode.data).first() if courseCodeExists: return render_template("courses/new.html", form = form, error = "Course code already exists") course = Course(form.name.data, form.coursecode.data, form.language.data, \ form.level.data, form.spots.data, form.course_location.data.id, form.description.data, form.registrationsopen.data) course.registrationsopen = form.registrationsopen.data db.session().add(course) db.session().commit() return redirect(url_for("courses_index"))
def courses_edit(course_id): course = Course.query.get(course_id) form = CourseForm(request.form, obj=course) if not form.validate(): return render_template("courses/edit.html", course = course, form = form) course.name = form.name.data course.coursecode = form.coursecode.data course.language = form.language.data course.level = form.level.data course.spots = form.spots.data course.course_location = form.course_location.data.id course.description = form.description.data course.registrationsopen = form.registrationsopen.data db.session().commit() return redirect(url_for("courses_index"))