Esempio n. 1
0
def show_journal(request):
    toolbox = toolbox_data([('История занятий', '/journal/lessons/history'),
                            ('Все оценки', '/journal/marks')])

    privilege_level = get_user_prior_group_number(request.user.id)

    if privilege_level == 1:
        lessons = get_schedule_for_student(request.user.id)

    elif privilege_level == 4:
        lessons = get_schedule_for_teacher(request.user.id)

    elif privilege_level > 4:
        all_groups = get_all_groups()
        return render(
            request, 'journal/manager_journal.html', {
                'study_groups': all_groups['study_groups'],
                'navbar': navbar_data(request),
                'toolbox': toolbox
            })

    return render(request, 'journal/apprentice_journal.html', {
        'navbar': navbar_data(request),
        'lessons': lessons,
        'toolbox': toolbox
    })
Esempio n. 2
0
def user_profile(request):
    user_id = request.user.id
    user_data = get_profile_data(user_id)
    privilege_level = get_user_prior_group_number(user_id)
    tools = [('Редактировать', '../{0}/edit'.format(user_id)),
             ('Выйти', '/accounts/logout/')]

    if privilege_level == 1:
        average_score = get_apprentice_average_score(user_data.id)
        attendance_score = get_apprentice_attendance_score(user_data.id)

        tools.append(
            ('Учебная группа',
             '/accounts/group/study/{0}'.format(user_data.study_group_id)))

        toolbox = toolbox_data(tools)
        return render(
            request, 'profiles/apprentice_page.html', {
                'profile_data': user_data,
                'average_score': average_score,
                'attendance_score': attendance_score,
                'toolbox': toolbox,
                'navbar': navbar_data(request)
            })
    elif privilege_level == 4:
        supervision_group = get_supervision_group(user_data.id)
        if supervision_group:
            tools.append(
                ('Учебная группа',
                 '/accounts/group/study/{0}'.format(supervision_group.id)))

        average_score = get_teacher_average_score(user_data.id)
        lessons_passed = get_all_teacher_lessons(user_data.id)

        toolbox = toolbox_data(tools)
        return render(
            request, 'profiles/teacher_page.html', {
                'profile_data': user_data,
                'supervision_group': supervision_group,
                'average_score': average_score,
                'lessons_passed': lessons_passed,
                'toolbox': toolbox,
                'navbar': navbar_data(request)
            })

    elif privilege_level == 5:
        toolbox = toolbox_data(tools)
        return render(
            request, 'profiles/manager_page.html', {
                'profile_data': user_data,
                'toolbox': toolbox,
                'navbar': navbar_data(request)
            })
Esempio n. 3
0
def edit_study_group(request, group_id):
    group_data = get_study_group_data(group_id)
    apprentices = get_study_group_apprentices(group_id)

    if request.method == 'POST':
        form = GroupEditForm(request.POST)

        new_specialisation = form.data.get('specialisation')
        new_supervisor = form.data.get('supervisor')
        new_headman = form.data.get('headman')
        new_methodist = form.data.get('methodist')

        set_study_group_settings(group_data, new_specialisation, new_headman,
                                 new_supervisor, new_methodist)

    available_settings = get_available_study_group_settings(group_data)
    available_settings['available_supervisors'].append(group_data.supervisor)

    return render(
        request, 'profiles/editors/group_editor.html', {
            'group_data':
            group_data,
            'available_supervisors':
            available_settings['available_supervisors'],
            'available_specialisations':
            available_settings['available_specialisations'],
            'available_methodists':
            available_settings['available_methodists'],
            'apprentices':
            apprentices,
            'navbar':
            navbar_data(request)
        })
Esempio n. 4
0
def view_study_group(request, group_id):
    group_data = get_study_group_data(group_id)
    apprentices = get_study_group_apprentices(group_id)

    apprentices_grid = get_group_statistics(apprentices, group_data.id)

    if group_data.headman:
        headman = group_data.headman
        try:
            headman.__setattr__('stats',
                                get_profile_statistics(headman.account_id))
        except AttributeError:
            headman.__setattr__('stats', ('N/A', 'N/A', 'N/A'))
    else:
        headman = None

    if group_data.methodist:
        methodist = group_data.methodist
        try:
            methodist.__setattr__('stats',
                                  get_profile_statistics(methodist.account_id))
        except AttributeError:
            methodist.__setattr__('stats', ('N/A', 'N/A', 'N/A'))
    else:
        methodist = None

    if group_data.supervisor:
        supervisor = group_data.supervisor
        try:
            supervisor.__setattr__(
                'stats', get_profile_statistics(supervisor.account_id))
        except AttributeError:
            supervisor.__setattr__('stats', ('N/A', 'N/A', 'N/A'))
    else:
        supervisor = None

    tools = [('Все группы', '../../all'),
             ('Статистика', '/statistics/groups/{0}'.format(group_id))]

    if request.user.has_perm('accounts.change_studygroup'):
        tools.append(('Редактировать', 'edit/'))

    toolbox = toolbox_data(tools)

    return render(
        request, 'profiles/groups/group_page.html', {
            'group_data': group_data,
            'headman': headman,
            'methodist': methodist,
            'supervisor': supervisor,
            'first_column': apprentices_grid[0],
            'second_column': apprentices_grid[1],
            'third_column': apprentices_grid[2],
            'toolbox': toolbox,
            'navbar': navbar_data(request)
        })
Esempio n. 5
0
def view_all_groups(request):
    groups_data = get_all_groups()
    separated_study_groups = separate_study_groups(groups_data['study_groups'])

    return render(
        request, 'profiles/groups/all_groups.html', {
            'high_school_groups': separated_study_groups['high'],
            'middle_school_groups': separated_study_groups['middle'],
            'primary_school_groups': separated_study_groups['primary'],
            'creative_groups': groups_data['creative_groups'],
            'navbar': navbar_data(request)
        })
Esempio n. 6
0
def show_marks(request):
    toolbox = toolbox_data([('Расписание', '/journal/'),
                            ('История занятий', '/journal/lessons/history')])

    privilege_level = get_user_prior_group_number(request.user.id)

    if privilege_level == 1:
        marks_dict = add_avg_score_to_sorted_marks(
            sort_marks_by_subject(get_all_marks_for_student(request.user.id)))
        return render(
            request, 'journal/marks/apprentice_marks.html', {
                'navbar': navbar_data(request),
                'marks': marks_dict,
                'toolbox': toolbox
            })

    elif privilege_level == 4:
        marks_list = sort_all_marks_for_teacher(
            get_all_marks_for_teacher(request.user.id))

        return render(
            request, 'journal/marks/teacher_marks.html', {
                'navbar': navbar_data(request),
                'all_marks': marks_list,
                'toolbox': toolbox
            })

    elif privilege_level > 4:
        marks_list = sort_all_marks_for_teacher(get_all_marks())
        toolbox = toolbox_data([('Список групп', '/journal/'),
                                ('Все занятия', '/journal/lessons/history')])

        return render(
            request, 'journal/marks/manager_marks.html', {
                'navbar': navbar_data(request),
                'all_marks': marks_list,
                'toolbox': toolbox
            })
Esempio n. 7
0
def return_book_page(request, fk):
    bor_book = LoanReceipts.objects.filter(book_id=fk,
                                           borrower_id=request.user)
    lib_book = Books.objects.get(ISBN_number=fk)
    person_data = navbar_data(request)
    if request.method == 'POST':
        bor_book.delete()
        return redirect('library_page')

    return render(request, 'library/return_book_page.html', {
        'book_detail': bor_book,
        'lib_book': lib_book,
        'navbar': person_data,
    })
Esempio n. 8
0
def book_borrow_page(request, pk):
    lib_book = Books.objects.get(ISBN_number=pk)
    disciples = Disciples.objects.all()
    person_data = navbar_data(request)

    if request.method == 'POST':
        form = BookAddForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('library_page')
    else:

        form = BookAddForm(initial={'book': pk, 'borrower': request.user})

    return render(
        request, 'library/book_detail.html', {
            'book_detail': lib_book,
            'navbar': person_data,
            'predmety': disciples,
            'add_book_form': form
        })
Esempio n. 9
0
def lesson_page(request, lesson_id=None):
    lesson_data = get_lesson_data_from_id(lesson_id)

    present_students, absent_students = get_on_lesson_students(
        lesson_data.group.id, lesson_id)
    privilege_level = get_user_prior_group_number(request.user.id)
    tools = [('Вернуться', '/journal/lessons/history')]

    if privilege_level > 3:
        tools += [('Редактировать',
                   '/journal/lessons/{0}/panel'.format(lesson_id)),
                  ('Удалить', '#')]

    toolbox = toolbox_data(tools)
    return render(
        request, 'journal/lesson/lesson_page.html', {
            'navbar': navbar_data(request),
            'toolbox': toolbox,
            'lesson_data': lesson_data,
            'lesson_marks': get_lesson_marks(lesson_id),
            'present_students': present_students,
            'absent_students': absent_students,
        })
Esempio n. 10
0
def lesson_history(request):
    privilege_level = get_user_prior_group_number(request.user.id)

    if privilege_level == 1:
        scheduled_lessons, latest_lessons = get_lesson_history_for_student(
            request.user.id)
        tools = [('Расписание', '/journal/'), ('Все оценки', '/journal/marks')]
    elif privilege_level == 4:
        scheduled_lessons, latest_lessons = get_lesson_history_for_teacher(
            request.user.id)
        tools = [('Расписание', '/journal/'), ('Все оценки', '/journal/marks')]
    elif privilege_level > 4:
        scheduled_lessons, latest_lessons = get_lesson_history_for_manager()
        tools = [('Все группы', '/journal/'), ('Все оценки', '/journal/marks')]

    toolbox = toolbox_data(tools)

    return render(
        request, 'journal/history/journal_history.html', {
            'navbar': navbar_data(request),
            'scheduled_lessons': scheduled_lessons,
            'latest_lessons': latest_lessons,
            'toolbox': toolbox
        })
Esempio n. 11
0
def show_library(request):
    lib_books = list(Books.objects.all())
    bor_books = list(LoanReceipts.objects.filter(borrower_id=request.user.id))
    # copy_lib_books = lib_books
    # isbn_arr_bor = []
    # for bor_book in bor_books:
    #     isbn_arr_bor.append(bor_book.book_id)
    # for counter, copy_lib_books in enumerate(copy_lib_books):
    #     print(counter)
    #     if copy_lib_books.ISBN_number in isbn_arr_bor:
    #         print(copy_lib_books.ISBN_number)
    #         copy_lib_books.pop(counter - 1)
    for bor_book in bor_books:
        for lib_book in lib_books:
            if bor_book.book.ISBN_number == lib_book.ISBN_number:
                lib_books.pop(lib_books.index(lib_book))
    person_data = navbar_data(request)
    return render(
        request, 'library/new_lib.html', {
            'all_books': lib_books,
            'person_data': person_data,
            'navbar': person_data,
            'my_books': bor_books
        })
Esempio n. 12
0
def overall_statistics(request):
    return render(request, 'statistics/overall_statistics.html',
                  {'navbar': navbar_data(request)})
Esempio n. 13
0
def lesson_panel(request, lesson_id=None):
    lesson_data = get_lesson_data_from_id(lesson_id)
    teacher = lesson_data.teacher

    # отметить отсутсвие
    if request.GET.get('remove-student'):
        set_student_absence(int(request.GET.get('remove-student')), lesson_id,
                            teacher.id)
        return redirect('/journal/lessons/{0}/panel'.format(lesson_id))

    # отметить присутсвие
    if request.GET.get('move-student'):
        set_student_presence(int(request.GET.get('move-student')), lesson_id)
        return redirect('/journal/lessons/{0}/panel'.format(lesson_id))

    # удаление оценки
    if request.GET.get('remove-mark'):
        remove_student_mark(int(request.GET.get('remove-mark')))
        return redirect('/journal/lessons/{0}/panel'.format(lesson_id))

    # уставновка оценки
    if request.POST:
        form = MarkPlacementForm(request.POST)

        if form.is_valid():
            try:
                set_student_mark(lesson_id,
                                 form.cleaned_data['holder'],
                                 form.cleaned_data['value'],
                                 form.cleaned_data['weight'],
                                 comment=form.cleaned_data['comment'])
            except DatabaseError:
                messages.warning(
                    request,
                    'Установка оценок доступна только для уроков 3-дневной давности.'
                )

            return redirect('/journal/lessons/{0}/panel'.format(lesson_id))

    # добавление домашнего задания
    if request.POST:
        homework_content = request.POST.get('content')
        homework_deadline = datetime.datetime.strptime(
            request.POST.get('deadline_date').replace('-', ' '), '%Y %m %d')
        homework_required = bool(request.POST.get('required'))

        set_homework(homework_content, homework_deadline, homework_required,
                     lesson_data)

        return redirect('/journal/lessons/{0}/panel'.format(lesson_id))

    present_students, absent_students = get_on_lesson_students(
        lesson_data.group.id, lesson_id)
    placed_lesson_homeworks = get_lesson_homework(lesson_id)

    return render(
        request, 'journal/lesson/lesson_panel.html', {
            'navbar': navbar_data(request),
            'lesson_data': lesson_data,
            'lesson_marks': get_lesson_marks(lesson_id),
            'lesson_homeworks': placed_lesson_homeworks,
            'present_students': present_students,
            'absent_students': absent_students
        })
Esempio n. 14
0
def edit_profile(request, user_id=None):
    if user_id is not None:
        user_data = get_profile_data(user_id)
    else:
        user_data = get_profile_data(request.user.id)

    user_group = get_user_prior_group_number(user_id)
    if request.user.id != user_id:
        if user_group == 1:
            if not request.user.has_perm('accounts.change_apprentice'):
                return HttpResponseForbidden()
        elif user_group == 4:
            if not request.user.has_perm('accounts.change_teachers'):
                return HttpResponseForbidden()
        elif user_group == 3:
            if not request.user.has_perm('accounts.change_teachers'):
                return HttpResponseForbidden()
        elif user_group == 2:
            if not request.user.has_perm('accounts.change_parents'):
                return HttpResponseForbidden()

    if request.method == 'POST':
        form = ProfileEditForm(request.POST, request.FILES)

        if form.is_valid():
            new_email = form.data.get('email')
            new_phone = form.data.get('phone')
            new_image = form.cleaned_data['profile_image']
            # new_status = form.data.get('status')

            if user_data.email != new_email:
                user_data.email = new_email

            if user_data.phone != new_phone:
                user_data.phone = new_phone

            if new_image is not None:
                user_data.profile_picture = new_image

            user_data.save()
            return redirect('/accounts/profile/{0}'.format(user_id))

    if user_group == 1:
        return render(request, 'profiles/editors/apprentice_editor.html', {
            'profile_data': user_data,
            'navbar': navbar_data(request)
        })
    elif user_group == 4:
        return render(request, 'profiles/editors/teacher_editor.html', {
            'profile_data': user_data,
            'navbar': navbar_data(request)
        })
    elif user_group == 3:
        return None
    elif user_group == 2:
        return None
    elif user_group == 5:
        return render(request, 'profiles/editors/manager_editor.html', {
            'profile_data': user_data,
            'navbar': navbar_data(request)
        })
Esempio n. 15
0
def profile(request, user_id=None):
    if user_id is not None:
        user_data = get_profile_data(user_id)
    else:
        user_data = get_profile_data(request.user.id)

    user_group = get_user_prior_group_number(user_id)
    tools = list()

    if user_group == 1:
        average_score = get_apprentice_average_score(user_data.id)
        attendance_score = get_apprentice_attendance_score(user_data.id)

        tools.append(
            ('Учебная группа',
             '/accounts/group/study/{0}'.format(user_data.study_group_id)))

        if request.user.has_perm('accounts.change_apprentice'):
            tools.append(('Редактировать', 'edit'))

        toolbox = toolbox_data(tools)
        return render(
            request, 'profiles/apprentice_page.html', {
                'profile_data': user_data,
                'average_score': average_score,
                'attendance_score': attendance_score,
                'toolbox': toolbox,
                'navbar': navbar_data(request)
            })
    elif user_group == 4:
        if request.user.has_perm('accounts.change_teachers'):
            tools.append(('Редактировать', 'edit'))

        average_score = get_teacher_average_score(user_data.id)
        lessons_passed = get_all_teacher_lessons(user_data.id)

        supervision_group = get_supervision_group(user_data.id)
        if supervision_group:
            tools.append(
                ('Учебная группа',
                 '/accounts/group/study/{0}'.format(supervision_group.id)))

        toolbox = toolbox_data(tools)
        return render(
            request, 'profiles/teacher_page.html', {
                'profile_data': user_data,
                'supervision_group': supervision_group,
                'average_score': average_score,
                'lessons_passed': lessons_passed,
                'toolbox': toolbox,
                'navbar': navbar_data(request)
            })
    elif user_group == 5:
        if request.user.has_perm('accounts.change_managers'):
            tools.append(('Редактировать', 'edit'))

        toolbox = toolbox_data(tools)
        return render(
            request, 'profiles/manager_page.html', {
                'profile_data': user_data,
                'toolbox': toolbox,
                'navbar': navbar_data(request)
            })
Esempio n. 16
0
def settings_page(request):
    if get_user_prior_group_number(request.user.id) < 5:
        return HttpResponseForbidden()

    if request.GET.get('fill_schedule'):
        command = request.GET.get('fill_schedule')
        today = timezone.now().date()
        if command == 'today':
            start_interval_replenish(today)

        elif command == 'week':
            week_start = today - timedelta(days=today.weekday())
            week_end = week_start + timedelta(days=6)
            start_interval_replenish(week_start, week_end)
        elif command == 'month':
            month_start = today.replace(day=1)
            next_month = today.replace(day=28) + timedelta(days=4)
            month_end = next_month - timedelta(days=next_month.day)

            start_interval_replenish(month_start, month_end)
            return redirect('/settings/')
        elif command == 'tomorrow':
            start_interval_replenish(today + timedelta(days=1))
        elif command == 'next_week':
            week_start = today - timedelta(days=today.weekday()) + timedelta(
                days=6)
            week_end = week_start + timedelta(days=7)
            start_interval_replenish(week_start, week_end)
        elif command == 'next_month':
            next_month_start = (today.replace(day=1) +
                                timedelta(days=32)).replace(day=1)
            next_month = next_month_start.replace(day=28) + timedelta(days=4)
            next_month_end = next_month - timedelta(days=next_month.day)

            start_interval_replenish(next_month_start, next_month_end)
        return redirect('/settings/')

    if request.GET.get('clear_schedule'):
        command = request.GET.get('clear_schedule')
        today = timezone.now().date()
        if command == 'today':
            start_interval_cleanup(today)
        elif command == 'week':
            week_start = today - timedelta(days=today.weekday())
            week_end = week_start + timedelta(days=6)

            start_interval_cleanup(week_start, week_end)
        elif command == 'month':
            month_start = today.replace(day=1)
            next_month = today.replace(day=28) + timedelta(days=4)
            month_end = next_month - timedelta(days=next_month.day)

            start_interval_cleanup(month_start, month_end)
        elif command == 'full':
            start_full_cleanup()

        return redirect('/settings/')

    if request.GET.get('load_schedule'):
        return redirect('/settings/')

    return render(request, 'settings/settings_page.html',
                  {'navbar': navbar_data(request)})