def edit_student(request): if request.method == 'GET': nid = request.GET.get('nid') sql1 = 'select id, title from class' class_list = sqlheper.get_list(sql1, []) sql2 = 'select id, name, class_id from student where id=%s' current_student_info = sqlheper.get_one(sql2, [ nid, ]) return render( request, 'edit_student.html', { 'class_list': class_list, 'current_student_info': current_student_info, }) else: nid = request.GET.get('nid') name = request.POST.get('name') class_id = request.POST.get('class_id') print(name, class_id, nid) sql3 = 'update student set name=%s, class_id=%s where id=%s' sqlheper.modify(sql3, [ name, class_id, nid, ]) return redirect('/students/')
def modal_add_teacher(request): ret = {'status': True, 'message': None} try: name = request.POST.get('teacher_name') class_id = request.POST.get('class_id') cid = class_id.split(',') print(cid) print(class_id) if len(name) > 0: sqlheper.modify("insert into teacher(name) value(%s)", [ name, ]) teacher_id = sqlheper.get_one( "select id from teacher where name=%s", [name], ) tid = teacher_id['id'] print(teacher_id['id']) for i in cid: sqlheper.modify( "insert into teacher2class(teacher_id,class_id) value(%s,%s)", [tid, i]) else: ret['status'] = False ret['message'] = "老师姓名不能为空" except Exception as e: ret['status'] = False ret['message'] = str(e) return HttpResponse(json.dumps(ret))
def edit_class(request): if request.method == "GET": nid = request.GET.get('nid') result = sqlheper.get_one("select id,class_name from t_class where id = %s", [nid, ]) print(result) return render(request, 'edit_class.html', {'result': result}) else: nid = request.GET.get('nid') class_name = request.POST.get('class_name') sqlheper.modify("update t_class set class_name=%s where id = %s", [class_name, nid, ]) return redirect('/classes/')
def edit_student(request): if request.method == "GET": nid = request.GET.get('nid') class_list = sqlheper.get_list("select id,class_name from t_class", []) print(class_list) current_sutdent_info = sqlheper.get_one("select id,student_name,class_id from t_student where id = %s", [nid, ]) print(current_sutdent_info) return render(request, 'edit_studemt.html', {'class_list': class_list, 'current_sutdent_info': current_sutdent_info}) else: nid = request.GET.get('nid') student_name = request.POST.get('student_name') sqlheper.modify("update t_student set student_name=%s where id = %s", [student_name, nid, ]) return redirect('/students/')
def edit_class(request): id = request.GET.get('nid') if request.method == 'GET': sql = "select id, title from class where id=%s" result = sqlheper.get_one(sql, [ id, ]) return render(request, 'edit_class.html', {'result': result}) else: title = request.POST.get('title') sql2 = "update class set title=%s where id=%s" sqlheper.modify(sql2, [ title, id, ]) return redirect('/classes/')
def edit_student(request): from utils import sqlheper if request.method == "GET": nid = request.GET.get('nid') class_list = sqlheper.get_list("select id,title from class", []) student_list = sqlheper.get_one( "select id,name,class_id from student where id=%s", [ nid, ]) return render(request, 'edit_student.html', { 'class_list': class_list, 'student_list': student_list }) else: name = request.POST.get("name") nid = request.GET.get('nid') cid = request.POST.get('class_id') sqlheper.modify("update student set name=%s,class_id=%s where id=%s", [name, cid, nid]) return redirect('/students')
def edit_students(request): if request.method == "GET": nid = request.GET.get('nid') class_list = sqlheper.get_list("select id,title from login_classtable", []) current_student_info = sqlheper.get_one( 'select id, name, class_id_id from login_student where id=%s', [ nid, ]) return render(request, "edit_students.html", { 'class_list': class_list, 'current_student_info': current_student_info }) else: nid = request.GET.get('nid') name = request.POST.get('name') class_id = request.POST.get('class_id') sqlheper.modify( 'update login_student set name=%s, class_id_id=%s where id=%s', [name, class_id, nid]) return redirect('/students/')
def edit_student(request): if request.method == "GET": nid = request.GET.get("nid") class_list = sqlheper.get_list("select id,name from class", []) current_student_info = sqlheper.get_one( 'select id,sname,class_id from student where id=%s', [ nid, ]) return render(request, 'edit_student.html', { 'class_list': class_list, 'current_student_info': current_student_info }) else: nid = request.GET.get("nid") name = request.POST.get('sname') class_id = request.POST.get('class_id') sqlheper.modify('update student set sname=%s,class_id=%s where id=%s', [ name, class_id, nid, ]) return redirect('/students/')
def editstudent(request): if request.method == "GET": nid = request.GET.get("nid") class_list = sqlheper.get_list("select id,title from myapp_class", []) current_student_info = sqlheper.get_one( "select id,stu_name,class_id_id from myapp_student where id=%s", [ nid, ]) return render(request, 'myApp/editstudent.html', { "class_list": class_list, "current_student_info": current_student_info }) else: nid = request.GET.get("nid") stu_name = request.POST.get("stu_name") class_id_id = request.POST.get("class_id_id") sqlheper.modify( "update myapp_student set stu_name=%s,class_id_id=%s where id=%s", [ stu_name, class_id_id, nid, ]) return redirect('/students/')