def modal_editorstudent(request): sqlhepr = SqlHeper() try: student_id = request.POST.get('nid') student_name = request.POST.get('student_name') class_id = request.POST.get('class_id') sqlhepr.updata_data( 'update students set name=%s,class_id=%s where id=%s', [student_name, class_id, student_id]) sqlhepr.commit_data() sqlhepr.close_data() context = {} context['status'] = 'success' except Exception as e: context['status'] = 'error' context['message'] = str(e) return JsonResponse(context)
def modal_editorclass(request): sqlhepr = SqlHeper() data = {} data['status'] = 'success' data['message'] = None try: nid = request.GET.get('nid') title = request.GET.get('title') if title.strip() != '': sqlhepr.updata_data("update classes set title=%s where id=%s", [title, nid]) sqlhepr.commit_data() sqlhepr.close_data() else: data['status'] = 'error' data['message'] = '输出的内容不能为空' except Exception as e: data['message'] = e return JsonResponse(data)
def editor_tearch(request): sqlhepr = SqlHeper() context = {} if request.method == 'POST': t_id = request.GET.get('t_id') #的到的是字符串 t2c_id = request.POST.get('t_c_ids') # 转化为列表 import re compile = re.compile('\d+') t2c_id = compile.findall(t2c_id) editor_class_ids = request.POST.getlist('editor_class_ids') t_name = request.POST.get('t_name') t_c = list(map(lambda x: (t_id, x), editor_class_ids)) sqlhepr.updata_data("update tearchs set tname=%s where id=%s", [t_name, t_id]) for i in t2c_id: sqlhepr.delete_data("delete from tearch2class where id=%s ", [i]) sqlhepr.commit_data() sqlhepr.updata_many_data( "insert into tearch2class (tearch_id,class_id)value(%s,%s)", t_c) sqlhepr.commit_data() sqlhepr.close_data() return redirect('/tearchs/') else: tid = request.GET.get('tid') tearch_name = sqlhepr.select_one_data( "select tname from tearchs where id=%s ", [tid]) current_class_list = sqlhepr.select_all_data( "select id ,class_id from tearch2class where tearch_id=%s", [tid]) tearch_class_ids = list(map(lambda x: x['id'], current_class_list)) current_class_ids = list( map(lambda x: x.get('class_id'), current_class_list)) class_list = sqlhepr.select_all_data("select id,title from classes ", []) sqlhepr.close_data() context['tearch_name'] = tearch_name context['current_class_ids'] = current_class_ids context['class_list'] = class_list context['tearch_class_ids'] = tearch_class_ids context['t_id'] = tid return render(request, 'editor_tearch.html', context)
def editorclass(request): nid = request.GET.get('nid') sqlhepr = SqlHeper() if request.method == "POST": date = request.POST.get('editorclass') sqlhepr.updata_data("update classes set title=%s where id=%s", [date, nid]) sqlhepr.commit_data() sqlhepr.close_data() return redirect('/classes/') else: result = sqlhepr.select_one_data( "select id,title from classes where id=%s", [ nid, ]) sqlhepr.close_data() context = {} context['editor_class'] = result return render(request, 'editorclass.html', context)
def editor(request): nid = request.GET.get('nid') sqlhepr = SqlHeper() if request.method == "POST": name = request.POST.get('editor') class_id = request.POST.get('class_name') sqlhepr.updata_data( "update students set name=%s,class_id=%s where id=%s", [name, class_id, nid]) sqlhepr.commit_data() sqlhepr.close_data() return redirect('/students/') else: result = sqlhepr.select_one_data( "select id,name ,class_id from students where id=%s", [ nid, ]) class_list = sqlhepr.select_all_data("select * from classes", []) sqlhepr.close_data() context = {} context['class_list'] = class_list context['result'] = result return render(request, "editorstudent.html", context)