Exemple #1
0
def update_student_document(student_doc: StudentDocument, updates: StudentUpdateModel):
    student_doc.first_name = updates.first_name
    student_doc.last_name = updates.last_name
    student_doc.grade = updates.grade
    student_doc.birth_month = updates.birth_month
    student_doc.birth_year = updates.birth_year
    student_doc.consent_form_object_name = updates.consent_form_object_name
    student_doc.save()
Exemple #2
0
async def get_student_consent_form_url(
    student_id: PydanticObjectId,
    token_data: TokenData = Depends(get_student_token_data),
):
    st_query = StudentDocument.objects(id=student_id)
    if len(st_query) == 0:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=f"Could not find student with id {student_id}",
        )

    student = st_query[0]
    if student.profile_uuid != token_data.id:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="Student id is associated with a different account",
        )

    object_name = student.consent_form_object_name
    if object_name is None:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="Student has not uploaded consent form yet",
        )

    response = create_presigned_url(object_name)

    if response is not None:
        return response

    return {"details": "Could not generate presigned url"}
def update_attendance(meeting_doc: MeetingDocument,
                      attendance: StudentMeetingAttendance):
    st_query = StudentDocument.objects(id=attendance.student_id)
    if len(st_query) < 1:
        print(
            "ERROR: update_student_attendance, could not find Student Document"
        )
    else:
        student = st_query[0]
        student.meetings_registered[str(
            attendance.meeting_id)] = attendance.attended
        update_count = 1 if attendance.attended else -1
        update_meeting_count(student,
                             meeting_doc.session_level,
                             attended=update_count)
        student.save()

    index = student_meeting_index(meeting_doc, attendance.student_id)
    if index is not None:
        meeting_doc.students[index]["attended"] = attendance.attended
        meeting_doc.save()
    else:
        print(
            "ERROR: update_student_attendance, student not registered for meeting"
        )
    def dict(self):
        students_to_return = []
        for st in self.students:
            query = StudentDocument.objects(id=st["student_id"])
            if len(query) < 1:
                print(
                    f"ERROR: student_id {st.student_id} in MeetingDocument but StudentDocument does not exist"
                )
            else:
                student = query[0]
                st["first_name"] = student.first_name
                st["last_name"] = student.last_name

            students_to_return.append(st)

        return {
            "uuid": self.uuid,
            "date_and_time": self.date_and_time,
            "duration": self.duration,
            "zoom_link": self.zoom_link,
            "miro_link": self.miro_link,
            "topic": self.topic,
            "session_level": self.session_level,
            "password": self.password,
            "students": students_to_return,
            "coordinator_notes": self.coordinator_notes,
            "student_notes": self.student_notes,
            "materials_uploaded": self.materials_uploaded,
        }
Exemple #5
0
async def update_student(
    registration: StudentMeetingRegistration,
    token_data: TokenData = Depends(get_student_token_data),
):

    current_user = get_current_user_doc(token_data)
    # FIXME: This assumes that the student id given in `registration`
    # is a valid student id for this account
    try:
        student = StudentDocument.objects(id=registration.student_id)[0]
    except Exception:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="Invalid student id",
        )

    try:
        meeting_doc = MeetingDocument.objects(uuid=registration.meeting_id)[0]
    except Exception:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="Invalid meeting id",
        )

    meeting_id = str(registration.meeting_id)
    if not registration.registered:
        remove_student_from_meeting(meeting_doc, registration.student_id)
        # Update StudentDocument `meetings_registered` to reflect changes
        if meeting_id in student.meetings_registered:
            # remove registration
            del student.meetings_registered[meeting_id]
            # decrement registered count
            update_meeting_count(student, meeting_doc.session_level, registered=-1)
            student.save()

        return {
            "details": f"Student with id {registration.student_id} removed from meeting list"
        }

    # otherwise add student to meeting
    student_info = StudentMeetingInfo(
        student_id=registration.student_id,
        email=current_user.email,
        guardians=current_user.guardians,
        account_uuid=token_data.id,
    )
    meeting_doc.students.append(student_info.dict())
    meeting_doc.save()

    # Update StudentDocument `meetings_registered`
    if meeting_id not in student.meetings_registered:
        # add the registration
        student.meetings_registered[meeting_id] = False
        # increment registered count
        update_meeting_count(student, meeting_doc.session_level, registered=1)
    student.save()
    return {
        "details": f"Student with id {registration.student_id} added to meeting list"
    }
async def update_student_verification(
        verification: StudentVerification,
        token_data: TokenData = Depends(get_admin_token_data),
):
    st_query = StudentDocument.objects(id=verification.student_id)
    if len(st_query) == 0:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="Could not find student with that student_id",
        )
    student = st_query[0]
    student.verification_status = verification.status
    student.save()
    return {
        "details":
        f"Updated verification status for student id {verification.student_id}"
    }
Exemple #7
0
def test_update_student_verification(mock_database):
    pre_save_user_auths()
    pre_save_profile_docs()
    response = client2.post("/token",
                            data={
                                "username": "******",
                                "password": "******"
                            })
    student_doc = StudentProfileDocument.objects(
        email="*****@*****.**")[0]
    student_id = student_doc.students[0].id
    json = response.json()
    access_token = json["access_token"]
    client.put(
        "/admin/update_student_verification",
        json=StudentVerification(student_id=student_id, status=True).dict(),
        headers={"Authorization": f"Bearer {access_token}"},
    )
    student = StudentDocument.objects(id=student_id).first()
    assert student.verification_status is True
Exemple #8
0
async def update_profile(
    new_profile: StudentProfileUpdateModel,
    token_data: TokenData = Depends(get_student_token_data),
):
    current_user = get_current_user_doc(token_data)
    current_user.email = new_profile.email
    current_user.guardians = [g.dict() for g in new_profile.guardians]
    current_user.mailing_lists = new_profile.mailing_lists

    # keep track of id's seen so we know what students to remove from account
    # student id is an Optional
    ids_in_request = [st.id for st in new_profile.students if st.id]
    # remove students not found in request
    for student_doc in current_user.students:
        if str(student_doc.id) not in ids_in_request:
            current_user.update(pull__students=student_doc)

    # update StudentDocuments
    # `new_profile.students` is a `List[StudentUpdateModel]`
    for student_update in new_profile.students:
        # add a new student if id is None
        if not student_update.id:
            new_student = StudentModel(
                **student_update.dict(), profile_uuid=token_data.id
            )
            student_document = StudentDoc(new_student)
            student_document.save()
            current_user.students.append(student_document)

        else:
            query = StudentDocument.objects(id=student_update.id)
            # if the student already existed update it
            if len(query) > 0:
                student_doc = query[0]
                update_student_document(student_doc, student_update)
            else:
                print("ERROR: could not find student id in update_profile")

    current_user.save()
    return current_user.dict()
Exemple #9
0
def test_update_student_attendance(mock_database):
    pre_save_user_auths()
    pre_save_profile_docs()
    pre_save_meetings()
    response = client2.post("/token",
                            data={
                                "username": "******",
                                "password": "******"
                            })
    meeting_id = MeetingDocument.objects().first().uuid
    json = response.json()
    access_token = json["access_token"]
    student_id = add_student_to_meeting()
    response = client.put(
        "/admin/update_student_attendance",
        json=StudentMeetingAttendance(meeting_id=meeting_id,
                                      student_id=student_id,
                                      attended=True).dict(),
        headers={"Authorization": f"Bearer {access_token}"},
    )
    assert response.status_code == 200
    student = StudentDocument.objects(id=student_id).first()
    assert student.meeting_counts["junior_a"]["attended"] == 1