Exemplo n.º 1
0
def edit_teacher(request):
    if request.method == 'GET':
        nid = request.GET.get('tid')
        name = request.POST.get('name')

        obj = SqlHeper()
        teacher_info = obj.get_one('select id,name from teacher where id=%s', [
            nid,
        ])
        class_list = obj.get_list('select id,title from classes')
        class_id_list = obj.get_list(
            'select class_id from teacher2class where teacher_id=%s', [
                nid,
            ])
        lst = []
        for item in class_id_list:
            lst.append(item['class_id'])
        class_id_list = lst
        return render(
            request, 'edit_teacher.html', {
                'teacher_info': teacher_info,
                'class_list': class_list,
                'class_id_list': class_id_list,
                'tid': nid
            })
    else:
        nid = request.GET.get('nid')
        name = request.POST.get('name')
        class_id_list = request.POST.getlist('clsid')
        obj = SqlHeper()
        obj.modify('update teacher set name=%s where id=%s', [name, nid])

        print(nid)

        obj.modify('delete from teacher2class where teacher_id=%s', [
            nid,
        ])

        lst = []
        for cls in class_id_list:
            lst.append((nid, cls))
        obj.multiple_modify(
            'insert into teacher2class(teacher_id,class_id) value(%s,%s)', lst)
        obj.close()

        return redirect('/teacher/')
Exemplo n.º 2
0
def edit_class(request, *args):
    obj = SqlHeper()
    if request.method == 'GET':
        #nid = request.GET.get('nid')
        nid = args[0]
        result = obj.get_one("select id,title from classes where id=%s", [nid])
        title = result['title']
        return render(request, "edit_class.html", {'nid': nid, 'title': title})
    else:
        #nid = request.POST.get('nid')
        nid = args[0]
        title = request.POST.get('title')
        obj.modify("update classes set title=%s where id=%s", [
            title,
            nid,
        ])
        return redirect('/classes/')