Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)