def invite_details( request, student_id, invite_id, ): invited_by = Student.objects.filter(id=invite_id).first() booking = StudentBooking.objects.filter(student_id=invite_id, approvement_status=True).first() if StudentBooking.objects.filter(student_id=invite_id, approvement_status=True).count() > 0: if booking is not None: room = Room.objects.filter(id=booking.room_id).first() s = RoomSerializer(room, many=False) d = StudentSerializer(invited_by, many=False) context = { 'student': d.data, 'room': s.data, 'response': 'Invite Details' } return Response(context, status=status.HTTP_201_CREATED) else: context = { 'response': 'That student\'s booking has not been approved' } return Response(context, status=status.HTTP_200_OK) else: context = {'response': 'Invalid Invite'} return Response(context, status=status.HTTP_200_OK)
def student_room(request, student_id): if StudentRoom.objects.filter(student_id=student_id).count() > 0: student = StudentRoom.objects.filter(student_id=student_id).first() room = Room.objects.filter(id=student.room_id).first() d = RoomSerializer(room, many=False) print(d.data) r_id = 0 if StudentSelections.objects.filter( student_id=student_id, pairing_status='Complete').count() > 0: r_id = StudentSelections.objects.filter( student_id=student_id, pairing_status='Complete').first().possible_roommate_id elif StudentSelections.objects.filter( possible_roommate_id=student_id, pairing_status='Complete').count() > 0: r_id = StudentSelections.objects.filter( possible_roommate_id=student_id, pairing_status='Complete').first().student_id if r_id != 0 and r_id is not None: roommate = Student.objects.filter(id=r_id).first() roommate_room = StudentRoom.objects.filter( student_id=roommate.id).first() if roommate is not None and roommate_room is not None: s = StudentSerializer(roommate, many=False) context = { 'room': d.data, 'roommate': s.data, 'response': 'Assigned Residence Details' } return Response(context, status=status.HTTP_200_OK) else: print('none') context = { 'room': d.data, 'response': 'Your Roommate Vacated', } print(context) return Response(context, status=status.HTTP_200_OK) else: context = { 'response': 'No roommate assigned to you yet', 'room': d.data, } return Response(context, status=status.HTTP_200_OK) else: context = { 'response': 'You are not assign a room yet', 'room': 'no room', 'roommate': 'no data', } print('here') return Response(context, status=status.HTTP_200_OK)
def admin_get_bookings(request): bookings = StudentBooking.objects.filter(approvement_status=False) if bookings.count() < 1: context = {'response': 'Currently No Bookings'} return Response(context, status=status.HTTP_201_CREATED) else: room_ids = [] for booking in bookings: room_ids.append(booking.room_id) rooms = Room.objects.filter(id__in=room_ids) s = RoomSerializer(rooms, many=True) context = {'response': 'Bookings', 'rooms': s.data} pprint(s.data) return Response(context, status=status.HTTP_200_OK)
def get_room_details(request, room_id, student_id): student = Student.objects.get(id=student_id) room = Room.objects.filter(id=room_id).first() ds = StudentRoom.objects.all() ids = [] for s_room in ds: ids.append(s_room.student_id) students = Student.objects.filter(gender=student.gender).exclude( id__in=set(ids)).exclude(id=student_id) s = RoomSerializer(room, many=False) d = StudentSerializer(students, many=True) pprint(d.data) context = {'room': s.data, 'students': d.data} return Response(context, status=status.HTTP_201_CREATED)
def get_booking_details(request, room_id): room = Room.objects.get(id=room_id) bookings = StudentBooking.objects.filter(room_id=room_id) ids = [] for booking in bookings: ids.append(booking.student.id) students = Student.objects.filter(id__in=ids) s = StudentSerializer(students, many=True) d = RoomSerializer(room, many=False) context = { 'bookings': s.data, 'room': d.data, 'response': 'Booking Details' } pprint(context) return Response(context, status=status.HTTP_200_OK)
def students_get_rooms(request): rooms = Room.objects.all().exclude(status_occupied='Occupied').exclude( status_occupied='Partial') # rooms = Room.objects.all() s = RoomSerializer(rooms, many=True) return Response(s.data, status=status.HTTP_201_CREATED)
def admin_room_details(request, room_id): room = Room.objects.filter(id=room_id).first() s = RoomSerializer(room, many=False) context = {'response': 'Room Details', 'room': s.data} return Response(context, status=status.HTTP_200_OK)
def admin_get_rooms(request): rooms = Room.objects.all() s = RoomSerializer(rooms, many=True) return Response(s.data, status=status.HTTP_201_CREATED)