def validate_status(self, value): if self.instance: print(self.instance.users) customer = self.instance.users.filter(is_customer=True).first() new_status = value if (self.instance.status == 'unconfirmed' and new_status == 'confirmed'): send_confirmed(user_number=customer.phone_number) if (self.instance.status == 'confirmed' and new_status == 'arrived'): send_arrived(user_number=customer.phone_number) return value
def change_status(self, new_status): '''Change the status based on the status coming in and the previous status. ''' if new_status == 'PICKING UP' and self.trip_status.name == 'REQUESTED': print('sending confirmed text') send_confirmed(self.customer.phone_number) self.trip_status = TripStatus.objects.get(name='PICKING UP') if new_status == 'ARRIVED' and self.trip_status.name == 'PICKING UP': self.trip_status = TripStatus.objects.get(name='ARRIVED') print('send arrived text') send_arrived(self.customer.phone_number) if new_status == 'FINISHED' and self.trip_status.name == 'ARRIVED': self.trip_status = TripStatus.objects.get(name='FINISHED') self.save()
def post(self, request, *args, **kwargs): trip_id = request.data.get('id') trip = Trip.objects.filter(id=trip_id).first() new_status = request.data.get('trip_status') if trip: if new_status == 'PICKING UP' and trip.trip_status.name == 'REQUESTED': print('sending confirmed text') send_confirmed(trip.customer.phone_number) trip.trip_status = TripStatus.objects.get(name='PICKING UP') if new_status == 'ARRIVED' and trip.trip_status.name == 'PICKING UP': trip.trip_status = TripStatus.objects.get(name='ARRIVED') print('send arrived text') send_arrived(trip.customer.phone_number) if new_status == 'FINISHED' and trip.trip_status.name == 'ARRIVED': trip.trip_status = TripStatus.objects.get(name='FINISHED') result = {} result['id'] = trip_id result['trip_status'] = trip.trip_status.name trip.save() return Response(result, status=status.HTTP_200_OK)