def addNews(): if request.method == "POST": if request.form['content'] == '' or request.form['content'] == None: print('Not exists') else: file = request.files['file'] # if user does not select file, browser also submit a empty part if file.filename == '': return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['IMG_FOLDER'], filename)) p = Post( title=request.form['title'], user=current_user, content=request.form['content'], date=strftime("%Y-%m-%d %H:%M:%S", gmtime()), img_url=filename, category=setCategory(request.form['category']), ) p.tags.extend(setTags(request.form.getlist('tags'))) db.session.add(p) db.session.commit() result = request.form['content'] return render_template('news/add&edit.html')
def addNews(courseid): c = db.session.query(Course).filter(Course.id == courseid).first() if request.method == "POST": if request.form['content'] == '' or request.form['content'] == None: print('Not exists') else: file = request.files['file'] # if user does not select file, browser also submit a empty part if file.filename == '': return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['IMG_FOLDER'], filename)) p = Post(title=request.form['title'], user=current_user, content=request.form['content'], date=strftime("%Y-%m-%d %H:%M:%S", gmtime()), img_url=filename, course=c) db.session.add(p) db.session.commit() return render_template('course/add-news.html', course=c)
def addCourse(): if request.method == "POST": if request.form['title'] == '' or request.form['title'] == None: print('Not exists') else: file = request.files['file'] # if user does not select file, browser also submit a empty part if file.filename == '': return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['VIDEO_FOLDER'], filename)) term = db.session.query(Term).filter( Term.year == request.form['term']).first() c = Course(title=request.form['title'], minor_title=request.form['minor_title'], about=request.form['about'], video_url=filename, syllabus=request.form['syllabus'], degree=request.form['degree'], homework=request.form['homework'], resources=request.form['resources'], term=term) teacher = db.session.query(Professor).filter( Professor.id == request.form['teacher']).first() c.teachers.extend([teacher]) db.session.add(c) db.session.commit() return render_template('course/add&edit.html', pageNum=4)
def editCourse(courseid): course = db.session.query(Course).filter(Course.id == courseid).first() if request.method == "POST": if request.form['title'] == '' or request.form['title'] == None: print('Not exists') else: file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['VIDEO_FOLDER'], filename)) course.video_url = filename term = db.session.query(Term).filter( Term.year == request.form['term']).first() course.title = request.form['title'] course.minor_title = request.form['minor_title'] course.about = request.form['about'] course.syllabus = request.form['syllabus'] course.degree = request.form['degree'] course.homework = request.form['homework'] course.resources = request.form['resources'] course.term = term if request.form['teacher'] != '': teacher = db.session.query(Professor).filter( Professor.id == request.form['teacher']).first() course.teachers.extend([teacher]) db.session.commit() return render_template('course/add&edit.html', course=course, pageNum=4)
def editNews(newsid): p = db.session.query(Post).filter(Post.id == newsid).first() if request.method == "POST": file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['IMG_FOLDER'], filename)) p.img_url = filename p.title = request.form['title'], p.content = request.form['content'], p.date = strftime("%Y-%m-%d %H:%M:%S", gmtime()), #p.category=setCategory(request.form['category']), db.session.commit() return render_template('news/add&edit.html', news=p)
def uploadHomework(courseid): stu = db.session.query(Authority).filter( Authority.name == "Student").first() course = db.session.query(Course).filter(Course.id == courseid).first() if stu in current_user.authorities and course in current_user.student.course: if request.method == "POST": file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['HOMEWORK_FOLDER'], filename)) u = UploadedHomework(url="filename", course=course, student=current_user.student) db.session.add(u) db.session.commit() return render_template('course/upload-homework.html', course=course, pageNum=4)