Esempio n. 1
0
def student_date_rangewise_list(request):
    var_end_date = datetime.today().date()
    var_start_date = var_end_date - timedelta(30)
    try:
        start_date = request.GET.get("date1", str(var_start_date))
        end_date = request.GET.get("date2", str(var_end_date))
        print(start_date)
        print(end_date)

        student_date_range = Student.objects.filter(
            date__gte=start_date, date__lte=end_date).order_by('-date')

        serializer = StudentSerializer(student_date_range, many=True)
        # response= student.values('name','teacher','roll')
        if start_date <= end_date:
            return Response(status=status.HTTP_200_OK, data=serializer.data)
        else:
            return Response('Invalid Date Range')

    except Exception as e:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                        data={
                            "success": False,
                            "error": e
                        })
Esempio n. 2
0
class EnrollmentbyGroupSerializer(serializers.ModelSerializer):

    studentEnrollment = StudentSerializer()

    class Meta:
        model = Enrollment
        fields = ['studentEnrollment']
Esempio n. 3
0
class EnrollmentSerializer(serializers.ModelSerializer):

    groupEnrollment = GroupSerializer()
    journeyEnrollment = JourneySerializer()
    studentEnrollment = StudentSerializer()

    class Meta:
        model = Enrollment
        fields = [
            'codeEnrollment', 'groupEnrollment', 'journeyEnrollment',
            'studentEnrollment', 'dateEnrollment', 'is_active'
        ]
Esempio n. 4
0
    def shiftless_students(self, request, pk=None):
        subject = get_object_or_404(Subject, id=pk)
        subject_spec = subject.subject_spec
        shiftless_students = list()
        shifts = Shift.objects.filter(subject=subject)
        c_types = LessonSpecification.LESSON_TYPE

        for student in subject.students.all():
            student_shifts = shifts.filter(student=student, subject=subject)
            student_classes = dict()
            for shift in student_shifts:
                lesson_spec = LessonSpecification.objects.filter(shift=shift)
                if lesson_spec and lesson_spec[0].c_type not in student_classes:
                    student_classes[lesson_spec[0].c_type] = 1
            for c_type, trans_c_type in c_types:
                subject_min_value = getattr(subject_spec, f"{c_type}_shifts")
                if subject_min_value != student_classes.get(c_type, 0):
                    delta = subject_min_value - student_classes.get(c_type, 0)
                    student_classes[str(trans_c_type)] = delta
                if c_type in student_classes:
                    del student_classes[c_type]
            if student_classes:
                student_info = StudentSerializer(student).data
                student_info.update(
                    RestrictedAppUserSerializer(student.app_user).data)
                student_info.update(dict(shiftless=student_classes))
                shiftless_students.append(student_info)
        return Response(shiftless_students)
Esempio n. 5
0
    def post(self, request):
        """
        按条件获取课程数据
        请求参数: user_id = ? , userkind = ?

        返回json: [
              {
                "lid": 809010001,
                "lname": "C语言程序设计01",
                "ltime": 12,
                "lclass_id": 1530501,
                "lclassroom_id": 101,
                "lteacher_id": 80901001
              },
              ...
            ]
        """

        # 获取请求数据
        querydict = request.data

        userkind = querydict.getlist("userkind")[0]
        user_id = querydict.getlist("user_id")[0]

        # 教师
        if userkind == "1":

            # 按照教师id获取课程数据
            condition_lesson = lesson_table.objects.filter(lteacher_id=user_id)
            condition_serializer = LessonSerializer(condition_lesson,
                                                    many=True)

            return Response(condition_serializer.data)

        # 学生
        if userkind == "2":

            # 获取该学生班号
            stu_querydict = student_table.objects.filter(sid=user_id)
            stu_info = StudentSerializer(stu_querydict, many=True).data

            print(stu_info)

            class_id = stu_info[0]["sclass"]

            # 按照班级id获取课程数据
            condition_lesson = lesson_table.objects.filter(lclass_id=class_id)
            condition_serializer = LessonSerializer(condition_lesson,
                                                    many=True)

            return Response(condition_serializer.data)
Esempio n. 6
0
    def post(self, request):
        # 获取请求参数
        querydict = request.data

        # 获取报告名,所属学生,所在班级
        lesson_id = querydict.getlist("lesson_id")[0]

        select_profession = report_table.objects.filter(rlesson_id=lesson_id)
        serializer = ReportSerializer(select_profession, many=True)

        report_data = serializer.data

        # 准备一个空列表装数据
        report_list = []

        for dict1 in report_data:
            # 获取报告名
            report_name = dict1["rname"]
            # 获取报告上传时间
            upload_time = dict1["rtime"]
            # 获取报告链接
            download_url = dict1["rfiles"]
            # 获取学生学号
            student_id = dict1["rstudent"]

            # 获取学生姓名
            student = student_table.objects.filter(sid=student_id)
            student_data = StudentSerializer(student, many=True)

            student_name = student_data.data[0]["sname"]

            data = {
                "student_name": student_name,
                "student_id": student_id,
                "report_name": report_name,
                "upload_time": upload_time,
                "download_url": download_url
            }

            report_list.append(data)

        return Response(report_list)
Esempio n. 7
0
class ShiftExchangeRequestSerializer(ModelSerializer):
    shift = ShiftSerializer()
    student = StudentSerializer()
    user = SerializerMethodField()
    subject_name = SerializerMethodField()
    capacity = SerializerMethodField()

    class Meta:
        model = ShiftExchangeRequest
        fields = "__all__"

    def get_user(self, request):
        return RestrictedAppUserSerializer(request.student.app_user).data

    def get_subject_name(self, request):
        subject = request.shift.subject
        course_subjects = CourseSubject.objects.filter(subject=subject)

        return " / ".join(map(lambda cs: cs.designation, course_subjects))

    def get_capacity(self, request):
        return f"{len(request.shift.student.all())} / {request.shift.vacancies}"
Esempio n. 8
0
    def post(self, request):
        """
        根据路由中班级id获取相关学生考勤

        路由: POST attendance/user_attendance/

        请求: user_id = ?   usrkind = ?

        """
        # 获取请求参数
        attendance = request.data

        userkind = attendance.getlist("userkind")[0]
        user_id = attendance.getlist("user_id")[0]

        # 教师
        if userkind == "1":

            try:
                user_attendance = teacher_attendance_table.objects.filter(
                    atuser_id=user_id)
            except:
                return Response({"error": "查询失败"})

            # 序列化
            tea_attendance_serializer = TeacherAttendanceSerializer(
                user_attendance, many=True)
            tea_attendance_dict = tea_attendance_serializer.data

            attendance_list = []

            for dict1 in tea_attendance_dict:
                id = dict1["id"]
                time = dict1["attime"]
                status = dict1["atstatus"]
                lesson_id = dict1["alesson"]
                user_id = dict1["atuser"]

                if status == 1:
                    status = "全勤"
                elif status == 2:
                    status = "迟到"
                elif status == 3:
                    status = "早退"
                elif status == 4:
                    status = "缺勤"
                elif status == 5:
                    status = "请假"

                # 获取老师姓名
                teacher = teacher_table.objects.filter(tid=user_id)
                teacher_data = TeacherSerializer(teacher, many=True)
                teacher_name = teacher_data.data[0]["tname"]

                # 获取课程名
                lesson = lesson_table.objects.filter(lid=lesson_id)
                lesson_data = LessonSerializer(lesson, many=True)
                lesson_name = lesson_data.data[0]["lname"]

                data = {
                    "id": id,
                    "name": teacher_name,
                    "time": time,
                    "lesson_name": lesson_name,
                    "status": status,
                }

                attendance_list.append(data)

            return Response(attendance_list)

        # 学生
        if userkind == "2":
            try:
                user_attendance = student_attendance_table.objects.filter(
                    asuser_id=user_id)
            except:
                return Response({"error": "查询失败"})

            # 序列化
            stu_attendance_serializer = StudentAttendanceSerializer(
                user_attendance, many=True)
            stu_attendance_dict = stu_attendance_serializer.data

            attendance_list = []

            for dict1 in stu_attendance_dict:
                id = dict1["id"]
                time = dict1["astime"]
                status = dict1["asstatus"]
                lesson_id = dict1["alesson"]
                user_id = dict1["asuser"]

                if status == 1:
                    status = "全勤"
                elif status == 2:
                    status = "迟到"
                elif status == 3:
                    status = "早退"
                elif status == 4:
                    status = "缺勤"
                elif status == 5:
                    status = "请假"

                # 获取学生姓名
                student = student_table.objects.filter(sid=user_id)
                student_data = StudentSerializer(student, many=True)
                student_name = student_data.data[0]["sname"]

                # 获取课程名
                lesson = lesson_table.objects.filter(lid=lesson_id)
                lesson_data = LessonSerializer(lesson, many=True)
                lesson_name = lesson_data.data[0]["lname"]

                data = {
                    "id": id,
                    "name": student_name,
                    "time": time,
                    "lesson_name": lesson_name,
                    "status": status,
                }

                attendance_list.append(data)

            return Response(attendance_list)