Ejemplo n.º 1
0
def student_periods_list(request):

    if request.method == 'POST':

        post = request.POST

        student_id = post["studentId"]

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

            if post["selectType"] == "0":

                if post["month"] == "13":

                    m_s = public_methods.mkt_time(post["year"] + "-" + "1" +
                                                  "-" + "1")
                    m_e = public_methods.mkt_time(
                        str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")

                elif post["month"] == "0":
                    m_s = public_methods.mkt_time(
                        str(int(post["year"]) - 1) + "-" + "12" + "-" + "1")
                    m_e = public_methods.mkt_time(post["year"] + "-" + "1" +
                                                  "-" + "1")

                else:

                    m_s = public_methods.mkt_time(post["year"] + "-" +
                                                  post["month"] + "-" + "1")

                    if post["month"] == "12":
                        m_e = public_methods.mkt_time(
                            str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")
                    else:
                        m_e = public_methods.mkt_time(
                            post["year"] + "-" + str(int(post["month"]) + 1) +
                            "-" + "1")

                period_list = mysql_db.ClassPeriodStudent.objects.filter(
                    period_time__gte=m_s,
                    period_time__lt=m_e).filter(user_id=student_id).values(
                        'user_id', 'name', 'period_data', 'period_time',
                        'class_time', 'class_teacher').order_by("period_time")
            else:

                period_list = mysql_db.ClassPeriodStudent.objects.filter(
                    user_id=student_id).values(
                        'user_id', 'name', 'period_data', 'period_time',
                        'class_time', 'class_teacher').order_by("period_time")

            print period_list.query

            period_list = json.dumps(list(period_list))

            return HttpResponse(period_list)
Ejemplo n.º 2
0
def period_statistics_teacher(request):

    if request.method == 'POST':

        post = request.POST

        teacher_id = post["teacherId"]

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

            if post["month"] == "13":

                m_s = public_methods.mkt_time(post["year"] + "-" + "1" + "-" +
                                              "1")
                m_e = public_methods.mkt_time(
                    str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")

            elif post["month"] == "0":
                m_s = public_methods.mkt_time(
                    str(int(post["year"]) - 1) + "-" + "12" + "-" + "1")
                m_e = public_methods.mkt_time(post["year"] + "-" + "1" + "-" +
                                              "1")

            else:

                m_s = public_methods.mkt_time(post["year"] + "-" +
                                              post["month"] + "-" + "1")

                if post["month"] == "12":
                    m_e = public_methods.mkt_time(
                        str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" +
                                                  str(int(post["month"]) + 1) +
                                                  "-" + "1")

            period_count = mysql_db.ClassPeriodStudent.objects.filter(
                period_time__gte=m_s,
                period_time__lt=m_e).filter(teacher_id=teacher_id).values(
                    'teacher_id', "class_teacher").annotate(
                        periodCount=Count('user_id')).order_by("teacher_id")

            print period_count.query

            teacher_list = json.dumps(list(period_count))

            return HttpResponse(teacher_list)
Ejemplo n.º 3
0
def period_teacher_self(request):

    if request.method == 'POST':

        post = request.POST

        teacher_id = post["teacherId"]

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

            if post["month"] == "13":

                m_s = public_methods.mkt_time(post["year"] + "-" + "1" + "-" +
                                              "1")
                m_e = public_methods.mkt_time(
                    str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")

            elif post["month"] == "0":
                m_s = public_methods.mkt_time(
                    str(int(post["year"]) - 1) + "-" + "12" + "-" + "1")
                m_e = public_methods.mkt_time(post["year"] + "-" + "1" + "-" +
                                              "1")

            else:

                m_s = public_methods.mkt_time(post["year"] + "-" +
                                              post["month"] + "-" + "1")

                if post["month"] == "12":
                    m_e = public_methods.mkt_time(
                        str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" +
                                                  str(int(post["month"]) + 1) +
                                                  "-" + "1")

            period_count = mysql_db.ClassPeriodTeacherSelf.objects.filter(
                period_time__gte=m_s,
                period_time__lt=m_e).filter(user_id=teacher_id).filter(
                    status=0).values('user_id', "name").annotate(
                        periodCount=Count('user_id')).order_by("id")

            print period_count.query

            teacher_list = json.dumps(list(period_count))

            return HttpResponse(teacher_list)

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

            period_commit_list = mysql_db.ClassPeriodTeacherSelf.objects.filter(
                user_id=teacher_id).filter(status=0).values().all()

            print period_commit_list.query

            teacher_list = json.dumps(list(period_commit_list))

            return HttpResponse(teacher_list)

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

            if post["month"] == "13":

                m_s = public_methods.mkt_time(post["year"] + "-" + "1" + "-" +
                                              "1")
                m_e = public_methods.mkt_time(
                    str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")

            elif post["month"] == "0":
                m_s = public_methods.mkt_time(
                    str(int(post["year"]) - 1) + "-" + "12" + "-" + "1")
                m_e = public_methods.mkt_time(post["year"] + "-" + "1" + "-" +
                                              "1")

            else:

                m_s = public_methods.mkt_time(post["year"] + "-" +
                                              post["month"] + "-" + "1")

                if post["month"] == "12":
                    m_e = public_methods.mkt_time(
                        str(int(post["year"]) + 1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" +
                                                  str(int(post["month"]) + 1) +
                                                  "-" + "1")

            wait_commit_list = mysql_db.ClassPeriodTeacherSelf.objects.filter(
                period_time__gte=m_s,
                period_time__lt=m_e).filter(user_id=teacher_id).filter(
                    status=0).values().all().order_by("id")

            print wait_commit_list.query

            wait_commit_list = json.dumps(list(wait_commit_list))

            return HttpResponse(wait_commit_list)
Ejemplo n.º 4
0
def period_statistics(request):

    if request.method == 'POST':

        post = request.POST

        print post

        if post["messageType"] == "list":
            year = "2021"
            post["year"] = year
            if post["month"] == "13":

                m_s = public_methods.mkt_time(post["year"] + "-" + "1" + "-" + "1")
                m_e = public_methods.mkt_time(str(int(post["year"])+1) + "-" + "1" + "-" + "1")

            elif post["month"] == "0":
                m_s = public_methods.mkt_time(str(int(post["year"])-1) + "-" + "12" + "-" + "1")
                m_e = public_methods.mkt_time(post["year"] + "-" + "1" + "-" + "1")
            else:

                m_s = public_methods.mkt_time(post["year"] + "-" + post["month"] + "-" + "1")

                if post["month"] == "12":
                    m_e = public_methods.mkt_time(str(int(post["year"])+1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" + str(int(post["month"])+1) + "-" + "1")

            # period_count = mysql_db.ClassPeriodTeacher.objects.filter(period_time__gt=m_s, period_time__lt=m_e).
            # values(
            #         'user_id',
            #         'name',
            # ).annotate(
            #         periodCount=Count('user_id')
            # ).order_by(
            #         "status",
            #         "user_id"
            # )

            period_count = mysql_db.ClassPeriodStudent.objects.filter(period_time__gte=m_s, period_time__lt=m_e).values(
                    'teacher_id',
                    'class_teacher'
            ).annotate(
                    periodCount=Count('teacher_id')
            ).order_by(
                    'teacher_id'
            )

            teacher_list = json.dumps(list(period_count))

            return HttpResponse(teacher_list)

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

            print post["messageType"]

            print post["year"]

            period_list = []

            for i in range(1, 13):

                m_s = public_methods.mkt_time(post["year"] + "-" + str(i) + "-" + "1")

                if i == 12:
                    m_e = public_methods.mkt_time(str(int(post["year"])+1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" + str(i+1) + "-" + "1")

                period_count = mysql_db.ClassPeriodStudent.objects.filter(
                        period_time__gte=m_s,
                        period_time__lt=m_e).count()

                period_list.append(period_count)

            period_month = return_function(period_list)
            return HttpResponse(period_month)

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

            print post["messageType"]

            print post["year"]

            period_income_list = []

            for i in range(1, 13):

                m_s = public_methods.mkt_time(post["year"] + "-" + str(i) + "-" + "1")

                if i == 12:
                    m_e = public_methods.mkt_time(str(int(post["year"])+1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" + str(i+1) + "-" + "1")

                period_income = mysql_db.ClassPeriodStudent.objects.filter(
                        period_time__gte=m_s,
                        period_time__lt=m_e
                ).values(
                        'price_period'
                ).aggregate(
                        period_income=Sum('price_period')
                )

                print period_income

                if period_income["period_income"] == None:
                    period_income["period_income"] = 0

                period_income_list.append(period_income["period_income"])

            period_month = return_function(period_income_list)
            return HttpResponse(period_month)

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

            print post["messageType"]

            print post["year"]

            sell_income_list = []

            for i in range(1, 13):

                m_s = public_methods.mkt_time(post["year"] + "-" + str(i) + "-" + "1")

                if i == 12:
                    m_e = public_methods.mkt_time(str(int(post["year"])+1) + "-" + "1" + "-" + "1")
                else:
                    m_e = public_methods.mkt_time(post["year"] + "-" + str(i+1) + "-" + "1")

                sell_income = role_db.Student.objects.filter(
                        entry_time__gte=m_s,
                        entry_time__lt=m_e
                ).filter(
                        status=1
                ).values(
                        'price'
                ).aggregate(
                        sell_income=Sum('price')
                )

                print sell_income

                if sell_income["sell_income"] == None:
                    sell_income["sell_income"] = 0

                sell_income_list.append(sell_income["sell_income"])

            period_month = return_function(sell_income_list)
            return HttpResponse(period_month)