Ejemplo n.º 1
0
def insert_users():

    # delete records (if any)
    UserModel.objects().delete()

    # loop through records
    for user in users:

        # find user_type record
        user['user_type'] = UserTypeModel.objects(
            user_type=user['user_type']).first()
        # create record
        user_model = UserModel(**user)
        # insert record
        user_model.save()
Ejemplo n.º 2
0
    def get(self, student_username, event_code):

        # query for grade_sheet
        student_model = UserModel.objects(username=student_username).first()
        event_model = EventModel.objects(event_code=event_code).first()
        grade_sheet_model = GradeSheetModel.objects(
            Q(student=student_model['user_id'])
            & Q(event=event_model['event_id'])).first()
        grade_sheet = grade_sheet_model.as_dict()

        # format student and instructor data
        user_fields = ['user_id', 'first_name', 'last_name']
        grade_sheet['student'] = {
            k: grade_sheet['student'][k]
            for k in user_fields
        }
        grade_sheet['instructor'] = {
            k: grade_sheet['instructor'][k]
            for k in user_fields
        }

        # return grade_sheet or 404 (not found)
        if grade_sheet:
            return {'grade_sheet': grade_sheet}
        return {'message': 'Grade sheet not found'}, 404
Ejemplo n.º 3
0
def insert_grade_sheets():

    # delete records (if any)
    GradeSheetModel.objects().delete()

    # loop through records
    for grade_sheet in grade_sheets:
        # find student_model
        grade_sheet['student'] = UserModel.objects(
            email_address=grade_sheet['student']).first()
        # find instructor_model
        grade_sheet['instructor'] = UserModel.objects(
            email_address=grade_sheet['instructor']).first()
        # find event_model
        grade_sheet['event'] = EventModel.objects(
            event_code=grade_sheet['event']).first()
        # create record
        grade_sheet_model = GradeSheetModel(**grade_sheet)
        # insert record
        grade_sheet_model.save()
Ejemplo n.º 4
0
    def get(self, student_username):

        # query for student
        student_model = UserModel.objects(username=student_username).first()
        student = student_model.as_dict()

        # get student grade_sheets
        student['grade_sheets'] = [
            grade_sheet.as_dict()
            for grade_sheet in GradeSheetModel.objects(student=student_model)
        ]

        # return student or 404 (not found)
        if student:
            return {'student': student}
        return {'message': 'Student not found'}, 404