def curriculum_list(request):

    curriculum_list_j = ""

    if request.method == 'POST':
        post = request.POST

        # curriculum_id = post["curriculum_id"]

        time.sleep(0.01)

        try:
            assortment_id = post["assortmentType"]
            get_curriculum_list = mysql_db.Curriculum.objects.filter(
                status="1", assortment_id=assortment_id)
        except:
            get_curriculum_list = mysql_db.Curriculum.objects.filter(
                status="1")

        try:
            curriculum = get_curriculum_list.values()[0]

            curriculum_list_j = serializers.serialize('json',
                                                      get_curriculum_list)

            response = curriculum_list_j
            return HttpResponse(response)

        except:

            response = public_methods.response_message("success", "", "100001")

            return JsonResponse(response)
Exemple #2
0
def user_login(request):

    if request.method == 'POST':

        post = request.POST
        user_name = post["userName"]
        password = post["password"]

        try:

            check_validity = mysql_db.Person.objects.get(user_name=user_name)
            # check_validity = mysql_db.Person.objects.filter(user_name=user_name).values('user_id', 'user_type')

            if check_validity.password == password:

                user_id = check_validity.user_id
                user_type = check_validity.user_type

                response_message = {
                    "message": "登陆成功",
                    "userId": user_id,
                    "userType": user_type
                }

                response = public_methods.response_message(
                    "success", response_message, "100001")

                # user_info.get_user_info((user_id, user_type))

                return JsonResponse(response)

            else:
                response = {"message": "用户名或密码错误"}
                return JsonResponse(
                    public_methods.response_message("fault", response,
                                                    "100005")).set_cookie(
                                                        "abc", "1")

        except:

            response = {"message": "用户名或密码错误"}
            return JsonResponse(
                public_methods.response_message("fault", response,
                                                "100005")).set_cookie(
                                                    "sessionid", "1111")
Exemple #3
0
def curriculum_add(request):

    if request.method == 'POST':
        post = request.POST

        curriculum_name = post["curriculumName"]
        assortment_id = post["assortmentId"]

        try:
            curriculum_id = mysql_db.Curriculum.objects.order_by(
                '-curriculum_id')[0].curriculum_id
            curriculum_id = int(curriculum_id) + 1
        except:
            curriculum_id = "1100001"

        add_curriculum = mysql_db.Curriculum(curriculum_name=curriculum_name,
                                             assortment_id=assortment_id,
                                             curriculum_id=curriculum_id,
                                             status="1")
        try:
            add_curriculum.save()
            response = {"message": "课程创建成功", "curriculumId": curriculum_id}
            result = "success"
            result_code = "1"

        except Exception as e:
            print e
            if e[0] == 1062:
                curriculum_status = mysql_db.Curriculum.objects.get(
                    curriculum_name=curriculum_name).status

                if curriculum_status == "1":
                    response = {"message": "课程名重复"}
                    result = "false"
                    result_code = "0"
                else:

                    curriculum_status_update = mysql_db.Curriculum.objects.get(
                        curriculum_name=curriculum_name)
                    curriculum_status_update.status = "1"
                    curriculum_status_update.save()

                    response = {
                        "message": "课程创建成功",
                        "curriculumId": curriculum_id
                    }
                    result = "success"
                    result_code = "1"

        return JsonResponse(
            public_methods.response_message(result, response, result_code))
Exemple #4
0
def class_list(request):

    # curriculum_list_j = ""

    if request.method == 'POST':
        post = request.POST

        week = post["week"]
        assortment_type = post["assortmentType"]
        class_id = []

        time.sleep(0.01)

        try:
            teacher_id = post["teacherId"]

            get_class_list = mysql_db.ClassInfo.objects.filter(
                status="1",
                class_week=week,
                assortment_type=assortment_type,
                teacher_id=teacher_id)

        except Exception as e:
            print e
            get_class_list = mysql_db.ClassInfo.objects.filter(
                status="1", class_week=week, assortment_type=assortment_type)

        print get_class_list.values("class_student")

        try:
            check_class_list = get_class_list.values()[0]

            class_list_j = serializers.serialize('json', get_class_list)

        except:

            response = public_methods.response_message("success", "", "100001")

            return JsonResponse(response)

        for i in range(len(get_class_list.values())):

            class_id.append(get_class_list.values()[i]["class_id"])

        response = class_list_j.encode('utf-8')
        return HttpResponse(response)
def curriculum_edit(request):

    if request.method == 'POST':
        post = request.POST

        curriculum_name = post["curriculumName"]
        assortment_id = post["assortmentId"]
        curriculum_id = post["curriculumId"]
        status = post["status"]

        update_curriculum = mysql_db.Curriculum.objects.get(
            curriculum_id=curriculum_id)

        update_curriculum.status = status
        update_curriculum.curriculum_name = curriculum_name
        update_curriculum.assortment_id = assortment_id

        try:

            update_curriculum.save()

            if status == "0":
                r_text = "删除成功"
            else:
                r_text = "修改成功"
            response = {"message": r_text, "curriculumId": curriculum_id}
            result = "success"
            result_code = "1"

        except Exception as e:

            print e
            if e[0] == 1062:
                curriculum_status = mysql_db.Curriculum.objects.get(
                    curriculum_name=curriculum_name).status

                if curriculum_status == "1":
                    response = {"message": "课程名重复"}
                    result = "false"
                    result_code = "0"

        return JsonResponse(
            public_methods.response_message(result, response, result_code))
Exemple #6
0
def class_eliminate(request):

    if request.method == 'POST':
        post = request.POST
        class_id = post["classId"]

        if post["messageType"] == "init":

            student_list_info = mysql_db.ClassRelationStudent.objects.filter(
                class_id=class_id, status=1).values("user_id", "name", "age")
            student_info = []

            for i in range(len(student_list_info)):

                student_id = student_list_info[i]["user_id"]
                student_name = student_list_info[i]["name"]
                left_period = role_db.Student.objects.filter(
                    user_id=student_id).values("left_periods")
                price_period = role_db.Student.objects.filter(
                    user_id=student_id).values("price_period")

                student_info.append({
                    "userId":
                    student_id,
                    "name":
                    student_name,
                    "leftPeriod":
                    left_period[0]["left_periods"],
                    "pricePeriod":
                    price_period[0]["price_period"]
                })

            response = {"studentInfo": student_info}

            return JsonResponse(response)

        if post["messageType"] == "teacherInit":

            student_list_info = mysql_db.ClassRelationStudent.objects.filter(
                class_id=class_id, status=1).values("user_id", "name", "age")
            student_info = []

            for i in range(len(student_list_info)):

                student_id = student_list_info[i]["user_id"]
                student_name = student_list_info[i]["name"]
                left_period = role_db.Student.objects.filter(
                    user_id=student_id).values("left_periods")
                price_period = role_db.Student.objects.filter(
                    user_id=student_id).values("price_period")

                student_info.append({
                    "userId":
                    student_id,
                    "name":
                    student_name,
                    "leftPeriod":
                    left_period[0]["left_periods"],
                    "pricePeriod":
                    price_period[0]["price_period"]
                })

            response = {"studentInfo": student_info}

            return JsonResponse(response)

        if post["messageType"] == "commit":

            print post
            # print post["studentLeftPeriod"]
            # print post["classInfo"]

            for i in range(len(eval(post["studentLeftPeriod"]))):

                if eval(post["studentLeftPeriod"])[i]["leftPeriod"] == "0":
                    response = {
                        "message": "消课失败",
                        "user": eval(post["studentLeftPeriod"])[i]["name"]
                    }
                    result = "false"
                    result_code = "0"

                    return JsonResponse(
                        public_methods.response_message(
                            result, response, result_code))

            student_list = eval(post["studentLeftPeriod"])
            class_id = eval(post["classInfo"])["class_id"]
            class_name = eval(post["classInfo"])["class_name"]
            teacher_id = eval(post["classInfo"])["teacher_id"]
            teacher_name = eval(post["classInfo"])["teacher_name"]
            status = 1
            period_time = int(
                time.mktime(time.strptime(post["periodDate"], '%Y-%m-%d')))
            # period_data = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            period_data = post["periodDate"]

            class_time = eval(
                post["classInfo"])["class_start_time"] + " - " + eval(
                    post["classInfo"])["class_end_time"]
            class_week = public_methods.week(
                eval(post["classInfo"])["class_week"])
            class_time_info = class_week + ":" + class_time
            student_name_list = []

            for i in range(len(student_list)):
                student_name_list.append(student_list[i]["name"])
                class_period_student_add = mysql_db.ClassPeriodStudent(
                    class_id=class_id,
                    class_name=class_name,
                    user_id=student_list[i]["userId"],
                    name=student_list[i]["name"],
                    status=1,
                    period_time=period_time,
                    period_data=period_data,
                    class_time=class_time_info,
                    class_teacher=teacher_name,
                    teacher_id=teacher_id,
                    price_period=student_list[i]["pricePeriod"])
                class_period_student_add.save()
                update_student_period = role_db.Student.objects.get(
                    user_id=student_list[i]["userId"])
                update_student_period.left_periods = int(
                    update_student_period.left_periods) - 1
                update_student_period.save()

            class_period_teacher_add = mysql_db.ClassPeriodTeacher(
                class_id=class_id,
                class_name=class_name,
                user_id=teacher_id,
                name=teacher_name,
                status=status,
                period_data=period_data,
                period_time=period_time,
                class_time=class_time_info,
                class_student=student_name_list)
            class_period_teacher_add.save()

            response = {"message": "成功"}
            result = "success"
            result_code = "1"

            return JsonResponse(
                public_methods.response_message(result, response, result_code))

        if post["messageType"] == "teacherCommit":

            print post
            # print post["studentLeftPeriod"]
            print eval(post["classInfo"])["id"]

            for i in range(len(eval(post["studentLeftPeriod"]))):

                if eval(post["studentLeftPeriod"])[i]["leftPeriod"] == "0":
                    response = {
                        "message": "消课失败",
                        "user": eval(post["studentLeftPeriod"])[i]["name"]
                    }
                    result = "false"
                    result_code = "0"

                    return JsonResponse(
                        public_methods.response_message(
                            result, response, result_code))

            commit_status = post["status"]
            commit_id = eval(post["classInfo"])["id"]
            student_list = eval(post["studentLeftPeriod"])
            class_id = eval(post["classInfo"])["class_id"]
            class_name = eval(post["classInfo"])["class_name"]
            teacher_id = eval(post["classInfo"])["user_id"]
            teacher_name = eval(post["classInfo"])["name"]
            status = 1
            # period_time = int(time.time())
            # period_data = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            period_time = int(
                time.mktime(time.strptime(post["periodDate"], '%Y-%m-%d')))
            # period_data = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            period_data = post["periodDate"]
            # class_time = eval(post["classInfo"])["class_start_time"]+" - " + eval(post["classInfo"])["class_end_time"]
            # class_week = public_methods.week(eval(post["classInfo"])["class_week"])
            # class_time_info = class_week + ":" + class_time
            class_time_info = eval(post["classInfo"])["class_time"]
            student_name_list = []

            update_teacher_left_period = role_db.Teacher.objects.get(
                user_id=teacher_id)
            update_teacher_left_period.left_commit_periods = int(
                update_teacher_left_period.left_commit_periods) - 1
            update_teacher_left_period.save()

            update_period_teacher = mysql_db.ClassPeriodTeacherSelf.objects.get(
                id=commit_id)

            if commit_status == "1":
                update_period_teacher.status = 1

                for i in range(len(student_list)):
                    student_name_list.append(student_list[i]["name"])
                    class_period_student_add = mysql_db.ClassPeriodStudent(
                        class_id=class_id,
                        class_name=class_name,
                        user_id=student_list[i]["userId"],
                        name=student_list[i]["name"],
                        status=1,
                        period_time=period_time,
                        period_data=period_data,
                        class_time=class_time_info,
                        class_teacher=teacher_name,
                        teacher_id=teacher_id,
                        price_period=student_list[i]["pricePeriod"])
                    class_period_student_add.save()
                    update_student_period = role_db.Student.objects.get(
                        user_id=student_list[i]["userId"])
                    update_student_period.left_periods = int(
                        update_student_period.left_periods) - 1
                    update_student_period.save()

                class_period_teacher_add = mysql_db.ClassPeriodTeacher(
                    class_id=class_id,
                    class_name=class_name,
                    user_id=teacher_id,
                    name=teacher_name,
                    status=status,
                    period_data=period_data,
                    period_time=period_time,
                    class_time=class_time_info,
                    class_student=student_name_list)
                class_period_teacher_add.save()

            if commit_status == "2":
                update_period_teacher.status = 2

            update_period_teacher.save()

            response = {"message": "成功"}
            result = "success"
            result_code = "1"

            return JsonResponse(
                public_methods.response_message(result, response, result_code))
Exemple #7
0
    def user_regist(self):

        if self.user_check == 1:

            if self.user_type == 1:
                try:
                    self.user_id = mysql_db.Person.objects.order_by(
                        '-user_id')[0].user_id
                except:
                    self.user_id = "10000001"
            elif self.user_type == 2:
                try:
                    self.user_id = mysql_db.Person.objects.order_by(
                        '-user_id')[0].user_id
                except:
                    self.user_id = "20000001"

            user_name = self.post['userName']
            password = self.post['password']
            self.user_type = self.param['userType']

            regist_persion = mysql_db.Person(
                user_id=self.user_id,
                user_name=user_name,
                password=password,
                user_type=self.user_type,
                create_time=public_methods.get_date_time(1, 1),
                update_time=public_methods.get_date_time(1, 1),
                status=0,
            )

            regist_persion.save()
            response = {
                "message": "注册成功",
                "userId": self.user_id,
                "userType": self.user_type
            }

            if self.user_type == "1":

                return HttpResponse(
                    public_methods.response_message("success", response,
                                                    "100001"))

            elif self.user_type == "2":

                return HttpResponse(
                    public_methods.response_message("success", response,
                                                    "100002"))

        elif self.user_check == 0:

            response = "注册失败,用户已存在"

            if self.user_type == "1":

                return HttpResponse(
                    public_methods.response_message("fault", response,
                                                    "100003"))

            elif self.user_type == "2":

                return HttpResponse(
                    public_methods.response_message("fault", response,
                                                    "100004"))
Exemple #8
0
def teacher_add(request):
    now_time = int(time.time())
    if request.method == 'POST':
        post = request.POST

        try:
            l_user_id = mysql_db.Teacher.objects.order_by(
                '-user_id')[0].user_id
            user_id = int(l_user_id) + 1

        except:
            user_id = "10000001"

        user_type = 1

        name = post["teacherName"]
        phone = post["teacherPhone"]
        create_time = now_time
        sex = post["teacherSex"]
        # age = post["teacherAge"]
        age = 100
        salary = post["teacherSalary"]
        school = post["teacherSchool"]
        entry_time = now_time
        status = 1
        user_name = phone
        pass_word = 123456
        teach_type = 1
        level = post["teacherLevel"]

        insert_person = mysql_db.Person(user_id=user_id,
                                        user_type=user_type,
                                        create_time=str(create_time),
                                        phone=phone,
                                        password=pass_word,
                                        status=status,
                                        sex=sex,
                                        user_name=user_name)

        insert_teacher = mysql_db.Teacher(teach_type=teach_type,
                                          age=age,
                                          salary=salary,
                                          entry_time=entry_time,
                                          school=school,
                                          name=name,
                                          user_id=user_id,
                                          status=status,
                                          level=level,
                                          left_commit_periods=0)

        try:
            insert_person.save()
            insert_teacher.save()
            response = {"message": "成功"}
            result = "success"
            result_code = "1"

        except Exception as e:
            print e
            response = {"message": "失败"}
            result = "false"
            result_code = "0"

        return JsonResponse(
            public_methods.response_message(result, response, result_code))
Exemple #9
0
def teacher_edit(request):
    now_time = int(time.time())
    if request.method == 'POST':
        post = request.POST

        teacher_id = post["teacherId"]

        message_type = post["messageType"]

        if message_type == "init":

            person_search = mysql_db.Person.objects.filter(user_id=teacher_id).values(
                    "phone", "sex")
            teacher_search = mysql_db.Teacher.objects.filter(user_id=teacher_id).values(
                    "age", "salary", "school", "name", "level")

            person_info = json.dumps(list(person_search)[0])

            teacher_info = json.dumps(list(teacher_search)[0])

            response = {"personInfo": person_info, "teacherInfo": teacher_info}

            return JsonResponse(response)

        if message_type == "edit":
            print "1"
            user_id = post["teacherId"]
            name = post["teacherName"]
            phone = post["teacherPhone"]
            update_time = now_time
            sex = post["teacherSex"]
            salary = post["teacherSalary"]
            level = post["teacherLevel"]
            school = post["teacherSchool"]

            update_person = mysql_db.Person.objects.get(user_id=user_id)
            update_person.phone = phone
            update_person.sex = sex
            update_person.update_time = update_time

            update_teacher = mysql_db.Teacher.objects.get(user_id=user_id)
            update_teacher.name = name
            update_teacher.salary = salary
            update_teacher.level = level
            update_teacher.school = school

            update_class_info = class_manager_db.ClassInfo.objects.filter(teacher_id=user_id)
            update_class_info.update(teacher_name=name)

            update_class_period_student = class_manager_db.ClassPeriodStudent.objects.filter(teacher_id=user_id)
            # update_class_period_student.class_teacher = name
            update_class_period_student.update(class_teacher=name)

            update_class_period_teacher = class_manager_db.ClassPeriodTeacher.objects.filter(user_id=user_id)
            update_class_period_teacher.update(name=name)

            update_class_period_teacherself = class_manager_db.ClassPeriodTeacherSelf.objects.filter(user_id=user_id)
            update_class_period_teacherself.update(name=name)

            update_class_relation_teacher = class_manager_db.ClassRelationTeacher.objects.filter(user_id=user_id)
            update_class_relation_teacher.update(name=name)

            try:
                update_person.save()
                update_teacher.save()

                response = {"message": "更新成功", "user_id": user_id}
                result = "success"
                result_code = "1"

            except Exception as e:
                print e
                response = {"message": "更新失败", "user_id": user_id}
                result = "false"
                result_code = "0"

            return JsonResponse(public_methods.response_message(result, response, result_code))
Exemple #10
0
def class_edit(request):

    if request.method == 'POST':
        post = request.POST
        class_id = post["classId"]

        if post["messageType"] == "init":

            class_info = mysql_db.ClassInfo.objects.filter(class_id=class_id, status=1).values(
                    "class_name", "class_start_time", "class_end_time", "curriculum_id", "curriculum_name")

            teacher_info = mysql_db.ClassRelationTeacher.objects.filter(class_id=class_id, status=1).values(
                    "user_id", "name")

            student_list_info = mysql_db.ClassRelationStudent.objects.filter(class_id=class_id, status=1).values(
                    "user_id", "name", "age", "periods", "left_periods")

            teacher_info = json.dumps(teacher_info[0])
            class_info = json.dumps(class_info[0])

            select_student_list = []

            for i in range(6):
                try:
                    select_student = student_list_info[i]
                except:
                    select_student = {"user_id": "1"}

                select_student_list.append(select_student)

            left_student_list = role_db.Student.objects.filter(
                    ~Q(user_id=select_student_list[0]["user_id"]),
                    ~Q(user_id=select_student_list[1]["user_id"]),
                    ~Q(user_id=select_student_list[2]["user_id"]),
                    ~Q(user_id=select_student_list[3]["user_id"]),
                    ~Q(user_id=select_student_list[4]["user_id"]),
                    ~Q(user_id=select_student_list[5]["user_id"])
            ).filter(status=1).filter(left_periods__gt=0
                 ).values("user_id", "name", "age", "periods", "left_periods")

            for i in range(len(select_student_list)):
                try:
                    select_student_list[i]["name"]
                except:
                    del select_student_list[i:]

            response = {"classInfo": class_info,
                        "teacherInfo": teacher_info,
                        "selectStudentList": json.dumps(list(select_student_list)),
                        "lefStudentList": json.dumps(list(left_student_list))
                        }

            return JsonResponse(response)

        if post["messageType"] == "edit":

            print class_id

            class_name = post["className"]
            # 课程信息
            curriculum_info = json.loads(post["curriculumInfo"])
            curriculum_name = curriculum_info["curriculum_name"]
            curriculum_id = curriculum_info["curriculum_id"]
            # 教师信息
            teacher_info = json.loads(post["teacherInfo"])
            teacher_name = teacher_info["name"]
            teacher_id = teacher_info["user_id"]

            # 学生信息
            student_list = eval(post["studentInfo"])
            student_name_list = []

            if student_list != "":

                for i in range(len(student_list)):
                    student_name_list.append(student_list[i]["name"])

            class_start_time = post["startTime"]
            class_time = ""
            class_end_time = post["endTime"]
            # class_week = post["week"]
            # assortment_type = post["assortmentType"]

            update_class = mysql_db.ClassInfo.objects.get(class_id=class_id)

            update_class.class_name = class_name
            update_class.curriculum_name = curriculum_name
            update_class.curriculum_id = curriculum_id
            update_class.teacher_id = teacher_id
            update_class.teacher_name = teacher_name
            update_class.class_start_time = class_start_time
            update_class.class_time = class_time
            update_class.class_end_time = class_end_time
            update_class.class_student = json.dumps(student_name_list)

            update_class_relation_teacher = mysql_db.ClassRelationTeacher.objects.get(class_id=class_id)
            update_class_relation_teacher.class_name = class_name
            update_class_relation_teacher.user_id = teacher_id
            update_class_relation_teacher.name = teacher_name
            # 需要改造成 json
            mysql_db.ClassRelationStudent.objects.filter(class_id=class_id).delete()

            try:
                update_class_relation_teacher.save()
                update_class.save()

                for i in range(len(student_list)):

                    add_class_relation_student = mysql_db.ClassRelationStudent(
                        class_id=class_id,
                        class_name=class_name,
                        user_id=student_list[i]["user_id"],
                        name=student_list[i]["name"],
                        age=student_list[i]["age"],
                        periods=student_list[i]["periods"],
                        left_periods=student_list[i]["left_periods"],
                        status="1"
                    )
                    add_class_relation_student.save()

                response = {"message": "班级更新成功", "class_id": class_id}
                result = "success"
                result_code = "1"

            except Exception as e:
                print e
                response = {"message": "班级更新失败", "class_id": class_id}
                result = "false"
                result_code = "0"

            return JsonResponse(public_methods.response_message(result, response, result_code))
Exemple #11
0
def student_add(request):
    now_time = int(time.time())
    if request.method == 'POST':
        post = request.POST

        try:
            l_user_id = mysql_db.Student.objects.order_by(
                '-user_id')[0].user_id
            user_id = int(l_user_id) + 1

        except:
            user_id = "20000001"

        user_type = 2

        contract_id = post["contractId"]
        name = post["studentName"]
        phone = post["studentPhone"]
        try:
            create_date = post["entryDate"]
            create_time = int(
                time.mktime(time.strptime(post["entryDate"], '%Y-%m-%d')))
        except:
            create_time = now_time
            create_date = now_time

        sex = post["studentSex"]
        age = post["studentAge"]
        price = post["studentPrice"]
        periods = post["studentPeriods"]
        left_periods = post["studentPeriods"]
        school = post["studentSchool"]
        try:
            entry_date = post["entryDate"]
            entry_time = int(
                time.mktime(time.strptime(post["entryDate"], '%Y-%m-%d')))
        except:
            entry_date = now_time
            entry_time = now_time
        status = 1
        user_name = user_id
        pass_word = user_id
        study_type = 210003

        insert_person = mysql_db.Person(user_id=user_id,
                                        user_type=user_type,
                                        create_time=str(create_time),
                                        create_date=create_date,
                                        phone=phone,
                                        password=pass_word,
                                        status=status,
                                        sex=sex,
                                        user_name=user_name)

        insert_student = mysql_db.Student(study_type=study_type,
                                          age=age,
                                          price=price,
                                          periods=periods,
                                          left_periods=left_periods,
                                          entry_time=entry_time,
                                          entry_date=entry_date,
                                          school=school,
                                          name=name,
                                          user_id=user_id,
                                          status=status,
                                          contract_id=contract_id,
                                          price_period=int(price) /
                                          int(periods))

        try:
            insert_person.save()
            insert_student.save()
            response = {"message": "成功"}
            result = "success"
            result_code = "1"

        except Exception as e:
            print e
            response = {"message": "失败"}
            result = "false"
            result_code = "0"
        # insert_person.save()
        # insert_student.save()
        # response = {"message": "成功"}
        # result = "success"
        # result_code = "1"

        return JsonResponse(
            public_methods.response_message(result, response, result_code))
Exemple #12
0
def user_info(request):

    if request.method == 'POST':

        message = {}

        post = request.POST
        user_id = post["userId"]
        user_type = post["userType"]
        message_type = post["messageType"]

        get_user_info = mysql_db.Person.objects.get(user_id=user_id)

        if message_type == "loginSearch":

            if user_type == "0" or user_type == "1":

                get_teacher_info = mysql_db.Teacher.objects.get(
                    user_id=user_id)

                phone = get_user_info.phone
                status = get_user_info.status
                sex = get_user_info.sex
                teach_type = get_teacher_info.teach_type
                age = get_teacher_info.age
                salary = get_teacher_info.salary
                school = get_teacher_info.school
                level = get_teacher_info.level
                name = get_teacher_info.name

                message = {
                    "phone": phone,
                    "sex": sex,
                    "teachType": teach_type,
                    "age": age,
                    "school": school,
                    "name": name
                }

            elif user_type == "2":

                get_student_info = mysql_db.Student.objects.get(
                    user_id=user_id)
                phone = get_user_info.phone
                status = get_user_info.status
                sex = get_user_info.sex
                study_type = get_student_info.study_type
                age = get_student_info.age
                price = get_student_info.price
                school = get_student_info.school
                periods = get_student_info.periods
                left_periods = get_student_info.left_periods
                name = get_student_info.name

                message = {
                    "phone": phone,
                    "status": status,
                    "sex": sex,
                    "age": age,
                    "school": school,
                    "name": name,
                    "studyType": study_type,
                    "periods": periods,
                    "leftPeriods": left_periods
                }
            message.setdefault('userId', user_id)
            message.setdefault('userType', user_type)

        response_message = {"message": message}
        response = public_methods.response_message("success", response_message,
                                                   "100001")
        return JsonResponse(response)
Exemple #13
0
def class_add(request):

    if request.method == 'POST':
        post = request.POST

        class_name = post["className"]
        # 课程信息
        curriculum_info = json.loads(post["curriculumInfo"])
        curriculum_name = curriculum_info["curriculum_name"]
        curriculum_id = curriculum_info["curriculum_id"]
        # 教师信息
        teacher_info = json.loads(post["teacherInfo"])
        teacher_name = teacher_info["name"]
        teacher_id = teacher_info["user_id"]

        # 学生信息
        student_list = eval(post["studentInfo"])
        student_name_list = []

        if student_list != "":

            for i in range(len(student_list)):
                student_name_list.append(student_list[i]["name"])

        class_start_time = post["startTime"]
        class_time = ""
        class_end_time = post["endTime"]
        class_week = post["week"]
        assortment_type = post["assortmentType"]

        try:
            class_id = mysql_db.ClassInfo.objects.order_by(
                '-class_id')[0].class_id
            class_id = int(class_id) + 1

        except:
            class_id = "1100001"

        add_class = mysql_db.ClassInfo(
            class_name=class_name,
            curriculum_name=curriculum_name,
            curriculum_id=curriculum_id,
            class_id=class_id,
            teacher_id=teacher_id,
            teacher_name=teacher_name,
            class_start_time=class_start_time,
            class_time=class_time,
            class_end_time=class_end_time,
            class_student=json.dumps(student_name_list),
            class_week=class_week,
            assortment_type=assortment_type,
            status="1")

        for i in range(len(student_list)):

            add_class_relation_student = mysql_db.ClassRelationStudent(
                class_id=class_id,
                class_name=class_name,
                user_id=student_list[i]["user_id"],
                name=student_list[i]["name"],
                age=student_list[i]["age"],
                periods=student_list[i]["periods"],
                left_periods=student_list[i]["left_periods"],
                status="1")
            add_class_relation_student.save()

        add_class_relation_teacher = mysql_db.ClassRelationTeacher(
            class_id=class_id,
            class_name=class_name,
            user_id=teacher_id,
            name=teacher_name,
            status="1")
        add_class_relation_teacher.save()

        try:
            add_class.save()
            response = {"message": "班级创建成功", "class_id": class_id}
            result = "success"
            result_code = "1"

        except Exception as e:
            print e

            response = {"message": "班级创建失败", "class_id": class_id}
            result = "false"
            result_code = "0"

        return JsonResponse(
            public_methods.response_message(result, response, result_code))
Exemple #14
0
def student_edit(request):
    now_time = int(time.time())
    if request.method == 'POST':
        post = request.POST

        student_id = post["studentId"]

        message_type = post["messageType"]

        if message_type == "init":

            person_search = mysql_db.Person.objects.filter(
                user_id=student_id).values("phone", "sex")
            student_search = mysql_db.Student.objects.filter(
                user_id=student_id).values("age", "price", "periods", "school",
                                           "name", "contract_id", "entry_time",
                                           "entry_date")

            person_info = json.dumps(list(person_search)[0])

            student_info = json.dumps(list(student_search)[0])

            response = {"personInfo": person_info, "studentInfo": student_info}

            return JsonResponse(response)

        if message_type == "edit":

            user_id = post["studentId"]
            name = post["studentName"]
            phone = post["studentPhone"]
            update_time = now_time
            sex = post["studentSex"]
            age = post["studentAge"]
            price = post["studentPrice"]
            # periods = post["studentPeriods"]
            # left_periods = post["studentPeriods"]
            try:
                create_date = post["entryDate"]
                create_time = int(
                    time.mktime(time.strptime(post["entryDate"], '%Y-%m-%d')))
            except:
                create_time = now_time
                create_date = now_time
            school = post["studentSchool"]
            contract_id = post["contractId"]

            update_persion = mysql_db.Person.objects.get(user_id=user_id)
            update_persion.phone = phone
            update_persion.sex = sex
            update_persion.update_time = update_time
            update_persion.create_date = create_date
            update_persion.create_time = create_time

            update_student = mysql_db.Student.objects.get(user_id=user_id)
            update_student.age = age
            update_student.name = name
            update_student.price = price
            # update_student.periods = periods
            update_student.school = school
            update_student.contract_id = contract_id
            update_student.entry_date = create_date
            update_student.entry_time = create_time

            try:
                update_persion.save()
                update_student.save()

                response = {"message": "更新成功", "user_id": user_id}
                result = "success"
                result_code = "1"

            except Exception as e:
                print e
                response = {"message": "更新失败", "user_id": user_id}
                result = "false"
                result_code = "0"

            return JsonResponse(
                public_methods.response_message(result, response, result_code))

        if message_type == "addPeriods":
            user_id = post["studentId"]
            add_periods = int(post["addPeriods"])

            update_student_periods = mysql_db.Student.objects.get(
                user_id=user_id)
            update_student_periods.periods = int(
                update_student_periods.periods) + add_periods
            update_student_periods.left_periods = int(
                update_student_periods.left_periods) + add_periods

            try:
                update_student_periods.save()

                response = {"message": "更新成功", "user_id": user_id}
                result = "success"
                result_code = "1"

            except Exception as e:
                print e
                response = {"message": "更新失败", "user_id": user_id}
                result = "false"
                result_code = "0"

            return JsonResponse(
                public_methods.response_message(result, response, result_code))
def UserInfo(request):

    if request.method == 'POST':

        post = request.POST
        user_id = post["userId"]
        user_type = post["userType"]
        phone = post["phone"]
        sex = post["sex"]
        try:
            age = post["age"]
        except:
            age = ""
        name = post["name"]
        school = post["school"]

        # if user_type == "1":
        #     teach_type = post["teachType"]

        print public_methods.get_date_time(1, 1)

        person_table_update = mysql_db.Person.objects.get(user_id=user_id)
        person_table_update.update_time = public_methods.get_date_time(1, 1)

        if sex != "" and sex != "undefined":
            person_table_update.sex = sex

        if phone != "":
            person_table_update.phone = phone

        if user_type == "0" or user_type == "1":

            teacher_table_update = mysql_db.Teacher.objects.get(
                user_id=user_id)

            if age != "":
                teacher_table_update.age = str(age)
            if school != "":
                teacher_table_update.school = school
            if name != "":
                teacher_table_update.name = name
            teacher_table_update.save()

        if user_type == 2:

            student_table_update = mysql_db.Student.objects.get(
                user_id=user_id)
            student_table_update.age = str(age)
            student_table_update.school = school
            student_table_update.save()

        person_table_update.save()

        response = {
            "message": "修改成功",
            "userId": user_id,
            "userType": user_type
        }

        if user_type == "0" or user_type == "1":

            return HttpResponse(
                public_methods.response_message("success", response, "100001"))

        elif user_type == "2":

            return HttpResponse(
                public_methods.response_message("success", response, "100002"))