Exemple #1
0
def section(request, sectionid):
    logged_in = request.user.is_authenticated
    if logged_in:
        the_profile = request.user.profile
        user_role = the_profile.role

    is_admin = logged_in and user_role == Profile.ACCESS_ADMIN
    is_prof = logged_in and user_role == Profile.ACCESS_PROFESSOR
    can_see_students = logged_in and user_role in (Profile.ACCESS_ADMIN,
                                                   Profile.ACCESS_PROFESSOR)

    qs = Section.objects.filter(id=sectionid)
    if qs.count() < 1:
        return HttpResponse("No such section")
    the_section = qs.get()

    data = {
        'section': the_section,
        'can_edit': is_admin,
        'can_refresh_items': is_prof
        and the_section.professor == the_profile.professor,
        'can_see_students': can_see_students,
    }
    data.update(next_prev(request, 'sections', sectionid))
    if can_see_students:
        data.update(
            filtered_table2(
                name='secstuds',
                qs=SectionStudent.objects.filter(section=the_section),
                filter=SectionStudentFilter,
                table=StudentInSectionTable,
                request=request,
                self_url=reverse('schooladmin:section', args=[sectionid]),
                click_url=reverse('schooladmin:sectionstudent',
                                  args=[DUMMY_ID]),
            ))
    data.update(
        filtered_table2(
            name='secitems',
            qs=the_section.sectionreferenceitem_set,
            filter=SectionItemFilter,
            table=ReferenceItemsForSectionTable,
            request=request,
            self_url=reverse('schooladmin:section', args=[sectionid]),
            click_url=reverse('sis:secitem', args=[DUMMY_ID]),
        ))

    if not logged_in:
        data['user'] = {'home_template': "schooladmin/home_guest.html"}
    return render(request, 'schooladmin/section.html', data)
Exemple #2
0
def semester(request, semester_id):
    logged_in = request.user.is_authenticated
    if logged_in:
        user_role = request.user.profile.role
    is_admin = logged_in and user_role == Profile.ACCESS_ADMIN

    qs = Semester.objects.filter(id=semester_id)
    if qs.count() < 1:
        return HttpResponse("No such semester")
    the_semester = qs.get()

    data = {'semester': the_semester, 'can_add': is_admin}
    data.update(next_prev(request, 'semesters', semester_id))
    data.update(
        filtered_table2(
            name='sections',
            qs=Section.objects.filter(semester=the_semester),
            filter=SectionFilter,
            table=SectionsTable,
            request=request,
            self_url=reverse('schooladmin:semester', args=[semester_id]),
            click_url=reverse('schooladmin:section', args=[DUMMY_ID]),
        ))
    if logged_in and user_role in (Profile.ACCESS_ADMIN,
                                   Profile.ACCESS_PROFESSOR):
        data.update(
            filtered_table2(
                name='students',
                qs=the_semester.students_attending(),
                filter=StudentFilter,
                table=StudentsTable,
                request=request,
                self_url=reverse('schooladmin:semester', args=[semester_id]),
                click_url=reverse('schooladmin:student', args=[DUMMY_ID]),
            ))
    data.update(
        filtered_table2(
            name='professors',
            qs=the_semester.professors_teaching(),
            filter=UserFilter,
            table=UsersTable,
            request=request,
            self_url=reverse('schooladmin:semester', args=[semester_id]),
            click_url=reverse('schooladmin:professor', args=[DUMMY_ID]),
        ))

    if not logged_in:
        data['user'] = {'home_template': "schooladmin/home_guest.html"}
    return render(request, 'schooladmin/semester.html', data)
Exemple #3
0
def course(request, courseid):
    logged_in = request.user.is_authenticated
    if logged_in:
        user_role = request.user.profile.role
    is_admin = logged_in and user_role == Profile.ACCESS_ADMIN

    qs = Course.objects.filter(id=courseid)
    if qs.count() < 1:
        return HttpResponse("No such course")
    the_course = qs.get()

    data = {'course': the_course, 'can_edit': is_admin}
    data.update(next_prev(request, 'courses', courseid))
    data.update(
        filtered_table2(
            name='sections',
            qs=Section.objects.filter(course=the_course),
            filter=SectionFilter,
            table=SectionForClassTable,
            request=request,
            self_url=reverse('schooladmin:course', args=[courseid]),
            click_url=reverse('schooladmin:section', args=[DUMMY_ID]),
        ))
    data.update(
        filtered_table2(
            name='prereqs',
            qs=Course.objects.filter(a_prerequisite__course=the_course),
            filter=CourseFilter,
            table=CoursesTable,
            request=request,
            page_size=5,
            self_url=reverse('schooladmin:course', args=[courseid]),
            click_url=reverse('schooladmin:course', args=[DUMMY_ID]),
        ))
    data.update(
        filtered_table2(
            name='neededby',
            qs=Course.objects.filter(a_course__prerequisite=the_course),
            filter=CourseFilter,
            table=CoursesTable,
            request=request,
            page_size=10,
            self_url=reverse('schooladmin:course', args=[courseid]),
            click_url=reverse('schooladmin:course', args=[DUMMY_ID]),
        ))

    if not logged_in:
        data['user'] = {'home_template': "schooladmin/home_guest.html"}
    return render(request, 'schooladmin/course.html', data)
Exemple #4
0
def user(request, userid):
    qs = User.objects.filter(id=userid)
    if qs.count() < 1:
        return HttpResponse("No such user")
    the_user = qs.get()

    logged_in = request.user.is_authenticated
    if logged_in:
        user_role = request.user.profile.role
    is_admin = logged_in and user_role == Profile.ACCESS_ADMIN

    if is_admin and request.method == 'POST':
        if request.POST.get('disbutton'):
            the_user.is_active = False
            the_user.save()
            messages.success(
                request,
                f'User {the_user.get_full_name()} has been disabled from login.'
            )
        elif request.POST.get('enabutton'):
            the_user.is_active = True
            the_user.save()
            messages.success(
                request,
                f'User {the_user.get_full_name()} has been enabled for login.')
        return redirect('schooladmin:users')

    if the_user.profile.role == Profile.ACCESS_STUDENT:
        if logged_in and (is_admin or user_role == Profile.ACCESS_PROFESSOR):
            return student(request, userid)
        else:
            return HttpResponse("Unauthorized")
    elif the_user.profile.role == Profile.ACCESS_PROFESSOR:
        return professor(request, userid)

    data = {
        'auser': the_user,
        'show_all': is_admin,
    }

    data.update(next_prev(request, 'users', userid))

    if is_admin:
        data.update(
            filtered_table2(
                name='received',
                qs=the_user.profile.sent_to.all(),
                filter=FullReceivedMessageFilter,
                table=MessageReceivedTable,
                request=request,
                wrap_list=False,
                self_url=reverse('schooladmin:user', args=[userid]),
                click_url=reverse('sis:viewmessage', args=[DUMMY_ID]),
            ))
        data.update(
            filtered_table2(
                name='sent',
                qs=the_user.profile.sent_by.all(),
                filter=FullSentMessageFilter,
                table=MessageSentTable,
                request=request,
                wrap_list=False,
                self_url=reverse('schooladmin:user', args=[userid]),
                click_url=reverse('sis:viewmessage', args=[DUMMY_ID]),
            ))

    return render(request, 'schooladmin/user.html', data)
Exemple #5
0
def professor(request, userid):
    logged_in = request.user.is_authenticated
    if logged_in:
        user_role = request.user.profile.role
    is_admin = logged_in and user_role == Profile.ACCESS_ADMIN

    qs = User.objects.filter(id=userid)
    if qs.count() < 1:
        return HttpResponse("No such user")
    the_prof = qs[0]

    if is_admin and request.method == 'POST':
        if request.POST.get('disbutton'):
            the_prof.is_active = False
            the_prof.save()
        elif request.POST.get('enabutton'):
            the_prof.is_active = True
            the_prof.save()
        return redirect('schooladmin:users')

    data = {'auser': the_prof, 'can_edit': is_admin}

    data.update(next_prev(request, 'professors', userid, fallback='users'))

    data.update(
        filtered_table2(
            name='semesters',
            qs=the_prof.profile.professor.semesters_teaching(),
            filter=SemesterFilter,
            table=SemestersSummaryTable,
            request=request,
            self_url=reverse('schooladmin:professor', args=[userid]),
            click_url=reverse('schooladmin:semester', args=[DUMMY_ID]),
        ))

    data.update(
        filtered_table2(
            name='sections',
            qs=the_prof.profile.professor.section_set,
            filter=SectionFilter,
            table=SectionsTable,
            request=request,
            self_url=reverse('schooladmin:professor', args=[userid]),
            click_url=reverse('schooladmin:section', args=[DUMMY_ID]),
        ))

    data.update(
        filtered_table2(
            name='items',
            qs=the_prof.profile.professor.referenceitem_set,
            filter=ItemFilter,
            table=ProfReferenceItemsTable,
            request=request,
            self_url=reverse('schooladmin:professor', args=[userid]),
            click_url=reverse('schooladmin:professor_item',
                              args=[userid, DUMMY_ID]),
        ))
    if is_admin:
        data.update(
            filtered_table2(
                name='received',
                qs=the_prof.profile.sent_to.filter(time_archived__isnull=True),
                filter=ReceivedMessageFilter,
                table=MessageReceivedTable,
                request=request,
                wrap_list=False,
                self_url=reverse('schooladmin:professor', args=[userid]),
                click_url=reverse('sis:viewmessage', args=[DUMMY_ID]),
            ))
        data.update(
            filtered_table2(
                name='sent',
                qs=the_prof.profile.sent_by.filter(time_archived__isnull=True),
                filter=SentMessageFilter,
                table=MessageSentTable,
                request=request,
                wrap_list=False,
                self_url=reverse('schooladmin:professor', args=[userid]),
                click_url=reverse('sis:viewmessage', args=[DUMMY_ID]),
            ))

    if not logged_in:
        data['user'] = {'home_template': "schooladmin/home_guest.html"}
    return render(request, 'schooladmin/professor.html', data)
Exemple #6
0
def student(request, userid):
    logged_in = request.user.is_authenticated
    if logged_in:
        user_role = request.user.profile.role
    is_admin = logged_in and user_role == Profile.ACCESS_ADMIN

    qs = User.objects.filter(id=userid)
    if qs.count() < 1:
        return HttpResponse("No such user")
    the_user = qs.get()

    if the_user.profile.role != Profile.ACCESS_STUDENT:
        return user(request, userid)

    if request.method == 'POST':
        if request.POST.get('disbutton'):
            the_user.is_active = False
            the_user.save()
        elif request.POST.get('enabutton'):
            the_user.is_active = True
            the_user.save()
        return redirect('schooladmin:users')

    data = {
        'auser': the_user,
        'can_edit': is_admin,
    }
    data.update(next_prev(request, 'students', userid, fallback='users'))

    data.update(
        filtered_table2(
            name='semesters',
            qs=the_user.profile.student.semesterstudent_set.all(),
            filter=SemesterStudentFilter,
            table=SemesterStudentSummaryTable,
            request=request,
            self_url=reverse('schooladmin:student', args=[userid]),
        ))

    data.update(
        filtered_table2(
            name='history',
            qs=the_user.profile.student.course_history(),
            filter=SectionStudentFilter,
            table=StudentHistoryTable,
            request=request,
            self_url=reverse('schooladmin:student', args=[userid]),
            click_url=reverse('schooladmin:sectionstudent', args=[DUMMY_ID]),
        ))

    data.update(
        filtered_table2(
            name='remaining',
            qs=the_user.profile.student.remaining_required_courses(),
            filter=CourseFilter,
            table=CoursesTable,
            request=request,
            self_url=reverse('schooladmin:student', args=[userid]),
            click_url=reverse('schooladmin:course', args=[DUMMY_ID]),
        ))
    data.update(
        filtered_table2(
            name='majorcourses',
            qs=the_user.profile.student.requirements_met_list(),
            filter=CourseFilter,
            table=MajorCoursesMetTable,
            request=request,
            click_url=reverse('schooladmin:course', args=[DUMMY_ID]),
        ))
    if is_admin:
        data.update(
            filtered_table2(
                name='received',
                qs=the_user.profile.sent_to.filter(time_archived__isnull=True),
                filter=ReceivedMessageFilter,
                table=MessageReceivedTable,
                request=request,
                wrap_list=False,
                self_url=reverse('schooladmin:student', args=[userid]),
                click_url=reverse('sis:viewmessage', args=[DUMMY_ID]),
            ))
        data.update(
            filtered_table2(
                name='sent',
                qs=the_user.profile.sent_by.filter(time_archived__isnull=True),
                filter=SentMessageFilter,
                table=MessageSentTable,
                request=request,
                wrap_list=False,
                self_url=reverse('schooladmin:student', args=[userid]),
                click_url=reverse('sis:viewmessage', args=[DUMMY_ID]),
            ))

    return render(request, 'schooladmin/student.html', data)
Exemple #7
0
def major(request, majorid):
    the_user = request.user
    logged_in = request.user.is_authenticated
    is_admin = logged_in and the_user.profile.role == Profile.ACCESS_ADMIN

    include_students = logged_in and the_user.profile.role in (Profile.ACCESS_ADMIN,
                                                               Profile.ACCESS_PROFESSOR)

    qs = Major.objects.filter(id=majorid)
    if qs.count() < 1:
        messages.error(request, "Something went wrong.")
        return HttpResponse("No such major", reason="Invalid Data", status=404)

    the_major = qs.get()

    data = {
        'major': the_major,
        'permit_edit': is_admin,
        'permit_new_course': is_admin,
        'include_students': include_students,
    }
    data.update(next_prev(request, 'majors', majorid))
    data.update(
        filtered_table2(
            name='profs',
            qs=User.objects.all().filter(profile__professor__major=the_major),
            filter=UserFilter,
            table=UsersTable,
            request=request,
            self_url=reverse('sis:major', args=[majorid]),
            click_url=reverse('schooladmin:professor', args=[DUMMY_ID]),
        ))

    data.update(
        filtered_table2(
            name='required',
            qs=Course.objects.filter(required_by=the_major),
            filter=CourseFilter,
            table=CoursesTable,
            request=request,
            self_url=reverse('sis:major', args=[majorid]),
            click_url=reverse('schooladmin:course', args=[DUMMY_ID]),
        ))

    data.update(
        filtered_table2(
            name='offered',
            qs=Course.objects.filter(major=the_major),
            filter=CourseFilter,
            table=CoursesForMajorTable,
            request=request,
            self_url=reverse('sis:major', args=[majorid]),
            click_url=reverse('schooladmin:course', args=[DUMMY_ID]),
        ))

    if include_students:
        data.update(
            filtered_table2(
                name='students',
                qs=User.objects.all().filter(profile__student__major=the_major),
                filter=UserFilter,
                table=StudentInMajorTable,
                request=request,
                self_url=reverse('sis:major', args=[majorid]),
                click_url=reverse('schooladmin:student', args=[DUMMY_ID]),
            ))

    if not logged_in:
        data['user'] = {'home_template': "schooladmin/home_guest.html"}
    return render(request, 'sis/major.html', data)
Exemple #8
0
def message(request, id, read_only=False):
    the_user = request.user
    the_profile = the_user.profile

    the_mess = Message.objects.get(id=id)
    is_recipient = the_mess.recipient == the_profile
    is_sender = the_mess.sender == the_profile
    is_student = the_profile.role == Profile.ACCESS_STUDENT
    is_admin = the_profile.role == Profile.ACCESS_ADMIN
    can_reply = the_mess.recipient == the_profile and not is_sender
    can_archive = not read_only and (is_recipient or is_sender)

    if the_mess is None:
        messages.error(request, 'Invalid message')
        return redirect('sis:messages')

    if not (is_sender or is_recipient) and not is_admin:
        messages.error(request, 'Invalid message')

    print(f'reply is {request.POST.get("reply", None)}')

    if not read_only:
        # mark our received messages read. Don't touch sent messages.
        if is_recipient and the_mess.time_read is None:
            the_mess.time_read = datetime.now(pytz.utc)
            the_mess.save()

        if request.method == 'POST':
            if request.POST.get('unarchive', None) is not None:
                messages.success(request, 'Message unarchived.')
                # why like this? Some messages are sent from you to you.
                if is_recipient:
                    the_mess.time_archived = None
                if is_sender:
                    the_mess.time_sender_archived = None
                the_mess.save()
                return redirect('sis:messages')

            elif request.POST.get('archive', None) is not None:
                messages.success(request, 'Message archived.')
                # why like this? Some messages are sent from you to you.
                if is_recipient:
                    the_mess.time_archived = datetime.now(pytz.utc)
                if is_sender:
                    the_mess.time_sender_archived = datetime.now(pytz.utc)
                the_mess.save()
                return redirect('sis:messages')

            elif request.POST.get('reply', None) is not None:
                response = Message.objects.create(
                    sender=the_profile,
                    recipient=the_mess.sender,
                    message_type=Message.REPLY_TYPE,
                    subject=f'Re: {the_mess.subject}',
                    body=request.POST.get("message_body", ""),
                    in_response_to=the_mess,
                )
                messages.success(request,
                                 f'Reply sent to {the_mess.sender.name}.')
                return redirect('sis:messages')

            elif is_admin and request.POST.get('approvedrop',
                                               None) is not None:
                the_student = Student.objects.get(
                    id=the_mess.support_data['student'])
                the_ssect = SectionStudent.objects.get(
                    id=the_mess.support_data['section'])
                the_student.drop_approved(sectionstudent=the_ssect,
                                          request_message=the_mess)
                messages.success(request, 'Drop Approved.')
                return redirect('sis:messages')

            elif is_admin and request.POST.get('rejectdrop', None) is not None:
                the_mess.time_handled = datetime.now(pytz.utc)
                the_mess.save()
                response = Message.objects.create(
                    sender=the_profile,
                    recipient=the_mess.sender,
                    message_type=Message.DROP_REJECTED_TYPE,
                    subject=f'Re: {the_mess.subject}',
                    body=request.POST.get("message_body", ""),
                    in_response_to=the_mess,
                )
                messages.success(
                    request,
                    f'Drop request rejection sent to {the_mess.sender.name}.')
                return redirect('sis:messages')

            elif is_admin and request.POST.get('approvemajor',
                                               None) is not None:
                the_student = Student.objects.get(
                    id=the_mess.support_data['student'])
                the_new_major = Major.objects.get(
                    id=the_mess.support_data['major'])
                the_student.major_change_approved(major=the_new_major,
                                                  request_message=the_mess)
                messages.success(request, 'Major Change Approved.')
                return redirect('sis:messages')

            elif is_admin and request.POST.get('rejectmajor',
                                               None) is not None:
                the_mess.time_handled = datetime.now(pytz.utc)
                the_mess.save()
                response = Message.objects.create(
                    sender=the_profile,
                    recipient=the_mess.sender,
                    message_type=Message.MAJOR_CHANGE_REJECTED_TYPE,
                    subject=f'Re: {the_mess.subject}',
                    body=request.POST.get("message_body", ""),
                    in_response_to=the_mess,
                )
                messages.success(
                    request,
                    f'Major change rejection sent to {the_mess.sender.name}.')
                return redirect('sis:messages')

            elif is_admin and request.POST.get('transcriptreq',
                                               None) is not None:
                the_mess.time_handled = datetime.now(pytz.utc)
                the_mess.save()
                the_student = Student.objects.get(
                    id=the_mess.support_data['student'])
                response = Message.objects.create(
                    sender=the_profile,
                    recipient=the_student.profile,
                    message_type=Message.TRANSCRIPT_TYPE,
                    subject="Your Transcript",
                    body="I'll be emailing it to you.",
                    in_response_to=the_mess,
                )
                messages.success(request, 'Transcript promised.')
                the_student = Student.objects.get(
                    id=the_mess.support_data['student'])
                # this generates and downloads the file.
                return transcript(request, userid=the_student.profile.user.id)

            else:
                messages.error(request, 'Something went wrong.')

    handled = the_mess.time_handled is not None
    handleable_message = the_mess.message_type in (Message.DROP_REQUEST_TYPE,
                                                   Message.MAJOR_CHANGE_TYPE)
    show_drop = is_recipient and the_mess.message_type == Message.DROP_REQUEST_TYPE \
        and not handled
    show_major = is_recipient and the_mess.message_type == Message.MAJOR_CHANGE_TYPE \
        and not handled
    show_transcript_req = is_recipient \
        and the_mess.message_type == Message.TRANSCRIPT_REQUEST_TYPE \
        and not handled

    message_archived = (is_recipient and the_mess.time_archived is not None
                        ) or (is_sender
                              and the_mess.time_sender_archived is not None)
    time_archived = the_mess.time_archived if is_recipient else the_mess.time_sender_archived

    detail_class = 'sis:viewmessage' if read_only else 'sis:message'
    block_class = 'users' if read_only else 'messages'

    data = {
        'auser': the_user,
        'message': the_mess,
        'show_approve_drop': not read_only and show_drop,
        'show_approve_major': not read_only and show_major,
        'show_transcript_req': not read_only and show_transcript_req,
        'show_archive': can_archive,
        'message_archived': message_archived,
        'time_archived': time_archived,
        'message_read': the_mess.time_read is not None,
        'message_handled': handled,
        'show_type': not is_student,
        'show_handled': handleable_message and not is_student,
        'show_read': True,
        'can_reply': not read_only and can_reply,
        'detail_class': detail_class,
        'block_class': block_class,
    }

    data.update(next_prev(request, 'received', id, fallback='sent'))

    return render(request, 'sis/message.html', data)