Exemplo n.º 1
0
class BookingSchema(ma.ModelSchema):
    class Meta:
        model = Booking
        jit = toastedmarshmallow.Jit

    booking_id = fields.Int(dump_only=True)
    booking_name = fields.Str()
    end_time = fields.DateTime()
    fees = fields.Str()
    room_id = fields.Int()
    start_time = fields.DateTime()
    invigilator_id = fields.Int(allow_none=True)
    office_id = fields.Int()
    sbc_staff_invigilated = fields.Int()
    booking_contact_information = fields.Str()

    invigilator = fields.Nested(
        InvigilatorSchema(only=('invigilator_id', 'invigilator_name',
                                'invigilator_notes')))
    room = fields.Nested(RoomSchema(exclude=(
        "booking",
        "office",
    )))
    office = fields.Nested(
        OfficeSchema(only=('appointments_enabled_ind', 'exams_enabled_ind',
                           'office_id', 'office_name', 'office_number',
                           'timezone')))
Exemplo n.º 2
0
class BookingSchema(ma.SQLAlchemySchema):
    class Meta:
        model = Booking
        include_relationships = True
        load_instance = True
        jit = toastedmarshmallow.Jit

    booking_id = fields.Int(dump_only=True)
    booking_name = fields.Str()
    end_time = fields.DateTime()
    fees = fields.Str()
    room_id = fields.Int()
    start_time = fields.DateTime()
    shadow_invigilator_id = fields.Int(allow_none=True)
    office_id = fields.Int()
    sbc_staff_invigilated = fields.Int()
    booking_contact_information = fields.Str()
    blackout_flag = fields.Str(allow_none=True)
    blackout_notes = fields.Str(allow_none=True)
    recurring_uuid = fields.Str(allow_none=True)

    room = fields.Nested(RoomSchema(exclude=(
        "booking",
        "office",
    )))
    office = fields.Nested(
        OfficeSchema(only=('appointments_enabled_ind', 'exams_enabled_ind',
                           'office_id', 'office_name', 'office_number',
                           'timezone')))

    #  NOTE:  The reason for the exclude, rather than just a single include, is because
    #         an include with a single field didn't seem to work.  When I added a second field, it worked.
    #         I only want a single field, so had to use an exclude instead.  ?????
    invigilators = fields.Nested(InvigilatorSchema(
        exclude=('contact_name', 'contact_email', 'contract_number',
                 'contract_expiry_date', 'invigilator_name',
                 'invigilator_notes', 'shadow_count', 'shadow_flag',
                 'contact_phone', 'deleted', 'office')),
                                 many=True)

    def update_invigilators(self, data):
        invigilator_data = data.get('invigilators')
        invigilator_list = []
        for invigilator in invigilator_data:
            id = invigilator.get('invigilator_id')
            invigilator_list.append(id)
        data['invigilators'] = invigilator_list
        return data

    @post_dump(pass_many=True)
    def fix_invigilators(self, data, many, **kwargs):
        if not many:
            data = self.update_invigilators(data)

        else:
            for booking in data:
                booking = self.update_invigilators(booking)

        return data
Exemplo n.º 3
0
class RoomList(Resource):

    rooms_schema = RoomSchema(many=True)

    @oidc.accept_token(require_token=True)
    def get(self):

        csr = CSR.find_by_username(g.oidc_token_info['username'])

        try:
            rooms = Room.query.filter_by(office_id=csr.office_id)
            result = self.rooms_schema.dump(rooms)
            return {'rooms': result.data, 'errors': result.errors}, 200

        except exc.SQLAlchemyError as error:
            logging.error(error, exc_info=True)
            return {"message": "api is down"}, 500
Exemplo n.º 4
0
class BookingSchema(ma.ModelSchema):
    class Meta:
        model = Booking
        jit = toastedmarshmallow.Jit

    booking_id = fields.Int(dump_only=True)
    booking_name = fields.Str()
    end_time = fields.DateTime()
    fees = fields.Str()
    room_id = fields.Int()
    start_time = fields.DateTime()
    invigilator_id = fields.Int()

    invigilator = fields.Nested(InvigilatorSchema())
    room = fields.Nested(RoomSchema(exclude=(
        "booking",
        "office",
    )))
Exemplo n.º 5
0
class RoomList(Resource):

    rooms_schema = RoomSchema(many=True)

    @jwt.has_one_of_roles([Role.internal_user.value])
    def get(self):

        csr = CSR.find_by_username(g.jwt_oidc_token_info['username'])

        office_id = request.args.get('office_id', csr.office_id)
        try:
            rooms = Room.query.filter_by(office_id=office_id)\
                              .filter(Room.deleted.is_(None))
            result = self.rooms_schema.dump(rooms)
            return {
                'rooms': result,
                'errors': self.rooms_schema.validate(rooms)
            }, 200

        except exc.SQLAlchemyError as error:
            logging.error(error, exc_info=True)
            return {"message": "api is down"}, 500
Exemplo n.º 6
0
class BookingSchema(BaseSchema):

    class Meta:
        model = Booking
        include_relationships = True
        load_instance = True
        unknown = EXCLUDE

    booking_id = fields.Int(dump_only=True)
    booking_name = fields.Str()
    end_time = fields.DateTime()
    fees = fields.Str()
    room_id = fields.Int()
    start_time = fields.DateTime()
    shadow_invigilator_id = fields.Int(allow_none=True)
    office_id = fields.Int()
    sbc_staff_invigilated = fields.Int()
    booking_contact_information = fields.Str()
    blackout_flag = fields.Str(allow_none=True)
    blackout_notes = fields.Str(allow_none=True)
    recurring_uuid = fields.Str(allow_none=True)
    stat_flag = fields.Boolean(allow_none=True)

    room = fields.Nested(RoomSchema(exclude=("office",)))
    office = fields.Nested(OfficeSchema(only=('appointments_enabled_ind', 'exams_enabled_ind', 'office_id',
                                              'office_name', 'office_number', 'timezone')))

    #  NOTE:  The reason for the exclude, rather than just a single include, is because
    #         an include with a single field didn't seem to work.  When I added a second field, it worked.
    #         I only want a single field, so had to use an exclude instead.  ?????
    invigilators = fields.Nested(InvigilatorSchema(exclude=( 'contact_email', 'contract_number',
                                                            'contract_expiry_date', 'invigilator_name',
                                                            'invigilator_notes', 'shadow_count', 'shadow_flag',
                                                            'contact_phone', 'deleted', 'office'
                                                            )), many=True)

    def update_invigilators(self, data):
        invigilator_data = data.get('invigilators')
        invigilator_list = []
        #  NOTE: The not none test put in by Chris to fix an error
        #        PUT /bookings/recurring/uuid call
        if invigilator_data is not None:
            for invigilator in invigilator_data:
                identifier = invigilator.get('invigilator_id')
                invigilator_list.append(identifier)
            data['invigilators'] = invigilator_list
        return data

    @post_dump(pass_many=True)
    def fix_invigilators(self, data, many, **kwargs):
        if not many:
            data = self.update_invigilators(data)

        else:
            for booking in data:
                booking = self.update_invigilators(booking)

        return data

    @pre_load
    def convert_bool_to_int(self, in_data, **kwargs):
        if type(in_data) == dict and 'sbc_staff_invigilated' in in_data and type(
                in_data['sbc_staff_invigilated']) == bool:
            in_data['sbc_staff_invigilated'] = 1 if in_data['sbc_staff_invigilated'] else 0
        return in_data