Esempio n. 1
0
    def post(self, request):
        teacher_form=AddTeacherForm(request.POST)
        if teacher_form.is_valid():
            Employee_num = request.POST.get("emp", "")
            teacher_num=Teacher.objects.filter(employee_num=Employee_num).first()
            if teacher_num:
                return JsonResponse({"status": "fail"}, safe=False)
            else:
                course_id_list_str=json.loads(request.POST.get("course_id_list",""))
                course_id_list = [int(course_id) for course_id in course_id_list_str]
                Name = request.POST.get("name", "")
                FN = request.POST.get("FN", "")
                LN = request.POST.get("LN", "")
                phone=request.POST.get("phone", "")
                teacher=Teacher(name=Name, first_name=FN, last_name=LN, employee_num=Employee_num, phone=phone)
                teacher.save()

                teacher.course.add(*course_id_list)
                context={}
                context["status"]= "success"

                op_log.send(
                    sender=Oplog,
                    admin=request.user,
                    reason="添加" + Name + "教师"
                )
                return JsonResponse({"status": "success"},safe=False)
        else:
            return JsonResponse({"status": "fail"}, safe=False)
Esempio n. 2
0
    def post(self,request):
        teacher_form=EditTeacherForm(request.POST)
        if teacher_form.is_valid():
            teacher_id=request.POST.get("teacher_id","")
            Name = request.POST.get("teacher_name", "")
            FN = request.POST.get("FN", "")
            LN = request.POST.get("LN", "")
            employeeNum = request.POST.get("teacher_num", "")
            phone = request.POST.get("teacher_phone", "")
            courses_int=[int(course_id) for course_id in request.POST.getlist('teacher_courses[]')]

            Teacher.objects.filter(pk=int(teacher_id)).update(name=Name, first_name=FN, last_name=LN,employee_num=employeeNum, phone=phone)
            teacher=Teacher.objects.filter(pk=teacher_id).first()

            teacher.course=courses_int
            teacher.save()

            op_log.send(
                sender=Oplog,
                admin=request.user,
                reason="修改" + Name + "教师"
            )
            return JsonResponse({"status":"success"},safe=False)
        else:
            return JsonResponse({"status":"fail"}, safe=False)
Esempio n. 3
0
    def post(self, request):
        excel_form = UploadExcelForm(request.POST, request.FILES)
        if excel_form.is_valid():
            wb = xlrd.open_workbook(
                filename=None, file_contents=request.FILES['excel'].read())  # 关键点在于这里
        else:
            msg = "请选择要导入的Excel表"
            return JsonResponse({
                'status': 'error',
                'msg': msg
            })
        table = wb.sheets()[0]
        table_num = table.nrows
        student_info_list = []
        for i in range(1, table_num):
            data = table.row_values(i)

            try:
                if not data[0] or not data[1] or not data[2] or not data[3]:
                    msg = "第" + str(i + 1) + "行数据不能为空!,导入失败!"
                    return JsonResponse({
                        'status': 'error',
                        'msg': msg
                    })
                single_student=Student.objects.filter(name=data[0], first_name=data[1], last_name=data[2], phone=str(self._to_int(data[3])))
                if single_student.count()>=1:
                    msg = "第" + str(i + 1) + "行" + data[0] + ":学生已存在!,导入失败!"
                    return JsonResponse({
                        'status': 'error',
                        'msg': msg
                    })

                else:
                    single_student = Student(name=data[0], first_name=data[1], last_name=data[2], phone=str(self._to_int(data[3])))
                    student_info_list.append(single_student)
            except:
                msg = "导入失败,请核查导入的表是否正确!"
                return JsonResponse({
                    'status': 'error',
                    'msg': msg
                })

        Student.objects.bulk_create(student_info_list)

        for student_info in student_info_list:
            op_log.send(
                sender=Oplog,
                admin=request.user,
                reason="导入"+student_info.name+"学生信息"
            )
        msg = "导入成功!"
        return JsonResponse({
            'status': 'ok',
            'msg': msg
        })
Esempio n. 4
0
    def post(self, request):
        checkbox_list = request.POST.getlist("hxy")
        for teacher_info_id in checkbox_list:
            Teacher.objects.filter(id=teacher_info_id).update(
                is_deleted=1, delete_date=datetime.date.today())

            teacher = Teacher.objects.filter(id=teacher_info_id).first()
            op_log.send(sender=Oplog,
                        admin=request.user,
                        reason="删除" + teacher.name + "教师")
        return HttpResponseRedirect(reverse("teacher"))
Esempio n. 5
0
    def post(self, request):
        checkbox_list = request.POST.getlist("hxy")
        for student_info_id in checkbox_list:
            Student.objects.filter(id=student_info_id).update(
                is_deleted=1, delete_date=datetime.date.today())

            student = Student.objects.filter(id=student_info_id).first()
            op_log.send(sender=Oplog,
                        admin=request.user,
                        reason="删除" + student.name + "学生")
        return HttpResponseRedirect(reverse('student'))
Esempio n. 6
0
 def post(self, request):
     student_form=EditStudentForm(request.POST)
     if student_form.is_valid():
         student_id = request.POST.get("student_id", "")
         Name = request.POST.get("student_name", "")
         FN = request.POST.get("student_FN", "")
         LN = request.POST.get("student_LN", "")
         phone = request.POST.get("student_phone", "")
         Student.objects.filter(pk=int(student_id)).update(name=Name, first_name=FN, last_name=LN, phone=phone)
         op_log.send(
             sender=Oplog,
             admin=request.user,
             reason="修改" + Name + "学生"
         )
         return JsonResponse({"status": "success"},safe=False)
     else:
         return JsonResponse({"status": "fail"}, safe=False)
Esempio n. 7
0
    def get(self, request):
        excel_id_list = request.session.get("excel_id_list", "")
        if "excel_id_list" in request.session.keys():
            del request.session['excel_id_list']
        if excel_id_list:
            emit_info = Teacher.objects.filter(id__in=excel_id_list, is_deleted=0)
        else:
            emit_info = Teacher.objects.filter(is_deleted=0)
        f = create_teacher_excel(emit_info)

        # 导出教师日志
        for teacher in emit_info:
            op_log.send(
                sender=Oplog,
                admin=request.user,
                reason="导出" + teacher.name + "教师信息"
            )

        current_time = time.strftime('%Y-%m-%d %H:%M:%S')
        response = HttpResponse(content_type='application/vnd.ms-excel')
        response['Content-Disposition'] = 'attachment; filename=%s.xls' % current_time
        f.save(response)
        return response
Esempio n. 8
0
 def post(self, request):
     student_add_form= AddStudentForm(request.POST)
     if student_add_form.is_valid():
         Name = request.POST.get("Name", "")
         FN = request.POST.get("FN", "")
         LN = request.POST.get("LN", "")
         Phone = request.POST.get("Phone", "")
         student=Student.objects.create(name=Name, first_name=FN, last_name=LN, phone=Phone)
         context = {
             "status": "success",
             "stu_id": student.id,
             "stu_Name": student.name,
             "stu_FN": student.first_name,
             "stu_LN": student.last_name,
         }
         op_log.send(
             sender=Oplog,
             admin=request.user,
             reason="添加"+Name+"学生"
         )
         return JsonResponse(context, safe=False)
     else:
         return JsonResponse({"status": "fail"}, safe=False)