Beispiel #1
0
def get_schedule_for_teacher(user_id):
    teacher_id = get_profile_from_user(user_id).id
    date = datetime.date.today()
    start_week = date - datetime.timedelta(date.weekday())
    end_week = start_week + datetime.timedelta(6)
    this_week_lessons = Lessons.objects.filter(
        date__range=[start_week, end_week],
        teacher_id=teacher_id,
    )
    return process_schedule_data_for_journal_view(this_week_lessons)
Beispiel #2
0
def get_schedule_for_student(user_id):
    student_group_id = get_profile_from_user(user_id).study_group_id
    date = datetime.date.today()
    start_week = date - datetime.timedelta(date.weekday())
    end_week = start_week + datetime.timedelta(6)
    this_week_lessons = Lessons.objects.filter(
        date__range=[start_week, end_week],
        study_group_id=student_group_id,
    )

    logger.info('Weekly schedule received for user: {0}'.format(user_id))
    return process_schedule_data_for_journal_view(this_week_lessons)
Beispiel #3
0
    def get(self, request):
        student_group_id = get_profile_from_user(
            request.user.id).study_group_id
        date = datetime.date.today()
        start_week = date - datetime.timedelta(date.weekday())
        end_week = start_week + datetime.timedelta(6)
        this_week_lessons = Lessons.objects.filter(
            date__range=[start_week, end_week],
            study_group_id=student_group_id)

        json_data = LessonSerializer(this_week_lessons, many=True)

        return Response(json_data.data)
Beispiel #4
0
    def get(self, request):
        student_group_id = get_profile_from_user(
            request.user.id).study_group_id

        homework = Homeworks.objects.filter(
            target_group=student_group_id,
            deadline_time__gte=datetime.datetime.now())
        if homework:
            json_data = HomeworkSerializer(homework, many=True)
        else:
            return Response(None)

        return Response(json_data.data)
Beispiel #5
0
def get_teacher_home_data(user_id):
    teacher_profile = get_profile_from_user(user_id)
    lessons, pretext, date = get_teacher_homepage_lessons(teacher_profile.id)
    homeworks = get_teacher_homepage_homework(teacher_profile.id, 7)
    marks = get_teacher_homepage_marks(teacher_profile.id, 3)

    result = {
        'lessons': lessons,
        'pretext': pretext,
        'date': date,
        'homeworks': homeworks,
        'marks': marks
    }

    return result
Beispiel #6
0
def get_apprentice_home_data(user_id):
    apprentice_profile = get_profile_from_user(user_id)

    lessons, pretext, date = get_student_homepage_lessons(apprentice_profile.study_group_id)
    homeworks = get_student_homepage_homework(apprentice_profile.study_group_id, 14)
    marks = get_student_homepage_marks(apprentice_profile.id, 14)

    result = {
        'lessons': lessons,
        'pretext': pretext,
        'date': date,
        'homeworks': homeworks,
        'marks': marks
    }

    return result
Beispiel #7
0
    def get(self, request):
        marks = Marks.objects.filter(
            holder=get_profile_from_user(request.user.id))

        # json_data = []
        # for _ in marks:
        #     json_data.append({
        #         'id': _.id,
        #         'value': _.value,
        #         'weight': _.weight,
        #         'date': _.rating_date,
        #         'subject': _.lesson.subject.title,
        #     })

        json_data = MarksSerializer(marks, many=True)

        return Response(json_data.data)
Beispiel #8
0
    def post(self, request):
        print(request)

        content = {}

        try:
            user = authenticate(username=request.data['username'],
                                password=request.data['password'])
        except KeyError:
            content = {
                'status': False,
                'message': 'Не все данные предоставлены!',
            }
            return Response(content)
        else:
            username = request.data['username']

            if user is not None:
                profile = get_profile_from_user(user.id)

                token = Token.objects.get_or_create(user_id=user.id)

                content = {
                    'status': True,
                    'user_id': profile.id,
                    'first_name': profile.first_name,
                    'last_name': profile.second_name,
                    'middle_name': profile.last_name,
                    'phone': profile.phone,
                    'email': profile.email,
                    'study_group': profile.study_group_id,
                    'token': token[0].key
                }
            else:
                content['status'] = False
                if User.objects.filter(username=username).count() > 0:
                    content['error'] = 'Неправильный пароль!'
                else:
                    content['error'] = 'Аккаунт не найден!'

        return Response(content)
Beispiel #9
0
def get_lesson_history_for_teacher(user_id):
    profile_data = get_profile_from_user(user_id)

    scheduled_lessons = []
    latest_lessons = []

    current_date = timezone.now().date()
    time_point = current_date - datetime.timedelta(days=7)
    # получаем список всех уроков за определенный период времени назад
    lessons_queryset = Lessons.objects.filter(teacher=profile_data.id,
                                              date__gt=time_point,
                                              date__lte=current_date +
                                              datetime.timedelta(days=1))

    for lesson in lessons_queryset.order_by('-date', 'order').values():
        new_lesson = get_lesson_info(lesson, full=False)
        if new_lesson.date >= current_date:
            scheduled_lessons.append(new_lesson)
        else:
            latest_lessons.append(new_lesson)

    return scheduled_lessons, latest_lessons
Beispiel #10
0
def get_all_marks_for_teacher(user_id):
    profile_data = get_profile_from_user(user_id)

    all_marks = Marks.objects.filter(appraiser_id=profile_data.id).exclude(
        value=0)
    return all_marks
Beispiel #11
0
def get_all_marks_for_student(user_id):
    profile_data = get_profile_from_user(user_id)

    all_marks = Marks.objects.filter(holder_id=profile_data.id).exclude(
        value=0)
    return all_marks