def delete_file(): if request.method == 'POST': filename = str(request.data, 'utf-8') file_path = os.path.join(app.config['COURSE_UPLOAD_FOLDER'], filename) os.remove(file_path) files = tools.listdir(app.config['COURSE_UPLOAD_FOLDER']) return render_template('file_list.html', files=files)
def upload_file(): if request.method == 'POST': file = request.files['upload_file'] filename = request.form['file_name'] file_path = os.path.join(app.config['COURSE_UPLOAD_FOLDER'], filename) file.save(file_path) files = tools.listdir(app.config['COURSE_UPLOAD_FOLDER']) return jsonify( {'html': render_template('file_list.html', files=files)})
def project_delete_file(): if request.method == 'POST': filename = str(request.data, 'utf-8') file_path = os.path.join(app.config['PROJECT_UPLOAD_FOLDER'], filename) os.remove(file_path) files = tools.listdir(app.config['PROJECT_UPLOAD_FOLDER']) return jsonify({ 'list': render_template('file_list.html', files=files), 'selector': render_template('fragment_editproject_file_selector.html', files=files) })
def edit_course(_id): # print(request.method) course = CourseModel.objects.get_or_404(_id=_id) CourseForm = model_form(CourseModel) form = CourseForm(request.form) courses = CourseModel.objects concepts = [] for course_temp in courses: if course_temp._id != course._id: concepts_temp = course_temp.concept for concept_temp in concepts_temp: concepts.append(concept_temp.id) # print(form.validate()) if request.method == 'POST': course.title = form.title.data course.text = form.text.data course.frame_head = form.frame_head.data course.frame_foot = form.frame_foot.data course.code = form.code.data course.course_id = form.course_id.data course.goal = form.goal.data concepts = Concept.objects concepts_temp = request.form.get('concept_temp').strip().split(',') concepts_list_temp = [] for string_temp in concepts_temp: flag = False # 如果存在相同concept则不保存 for concept in concepts: if concept.name == string_temp: flag = True break if not flag: concept_save = Concept(name=string_temp) concept_save.save() concepts_list_temp.append(string_temp) course.concept = concepts_list_temp print(course.concept) print(type(course.concept[0])) course.save() # flash('Course updated.','success') return redirect(url_for('edit_course', _id=_id)) files = tools.listdir(app.config['COURSE_UPLOAD_FOLDER']) # print(files) return render_template('editcourse.html', course=course, form=form, files=files, concepts=concepts)
def project_upload_file(): if request.method == 'POST': file = request.files['project_upload_file'] filename = request.form['file_name'] file_path = os.path.join(app.config['PROJECT_UPLOAD_FOLDER'], filename) file.save(file_path) files = tools.listdir(app.config['PROJECT_UPLOAD_FOLDER']) return jsonify({ 'list': render_template('file_list.html', files=files), 'selector': render_template('fragment_editproject_file_selector.html', files=files) })
def add_course(): course = CourseModel.objects.get_or_404(course_id=0) CourseForm = model_form(CourseModel) form = CourseForm(request.form) concepts = Concept.objects all_id = CourseModel.objects.order_by('course_id').fields(course_id=1) max_id = all_id[len(all_id) - 1].course_id + 1 if request.method == 'POST': title = form.title.data text = form.text.data frame_head = form.frame_head.data frame_foot = form.frame_foot.data code = form.code.data goal = form.goal.data course_id = form.course_id.data concept = request.form.get('concept_temp') concepts_temp = concept.strip().split(',') concepts_list_temp = [] for string_temp in concepts_temp: flag = False for concept in concepts: if concept.name == string_temp: flag = True break if not flag: concept_save = Concept(name=string_temp) concept_save.save() concepts_list_temp.append(string_temp) new_course = CourseModel(title=title, text=text, frame_head=frame_head, frame_foot=frame_foot, goal=goal, code=code, course_id=course_id, concept=concepts_list_temp) new_course.save(force_insert=True) return redirect(url_for('Admin')) course.course_id = max_id files = tools.listdir(app.config['COURSE_UPLOAD_FOLDER']) return render_template('editcourse.html', course=course, form=form, files=files, concepts=concepts)
def edit_project(_id): project = ProjectModel.objects.get_or_404(_id=_id) ProjectForm = model_form(ProjectModel) form = ProjectForm(request.form) if request.method == 'POST': project.title = form.title.data project.text = form.text.data project.project_id = form.project_id.data project.test = form.test.data project.save() # flash('Course updated.','success') return redirect(url_for('edit_project', _id=_id)) files = tools.listdir(app.config['PROJECT_UPLOAD_FOLDER']) # print(files) return render_template('editproject.html', project=project, form=form, files=files)
def add_project(): project = ProjectModel(title="", text="", test="") ProjectForm = model_form(ProjectModel) form = ProjectForm(request.form) all_id = ProjectModel.objects.order_by('project_id').fields(project_id=1) max_id = 1 if len(all_id) == 0 else all_id[len(all_id) - 1].project_id + 1 if request.method == 'POST': title = form.title.data text = form.text.data test = form.test.data project_id = form.project_id.data new_project = ProjectModel(title=title, text=text, project_id=project_id, test=test) new_project.save(force_insert=True) return redirect(url_for('show_projectpages')) project.project_id = max_id files = tools.listdir(app.config['PROJECT_UPLOAD_FOLDER']) return render_template('editproject.html', project=project, form=form, files=files)