Пример #1
0
    def put(self, request, pk):
        """PUT allows updating in-air status."""
        try:
            user = User.objects.get(pk=int(pk))
        except User.DoesNotExist:
            return HttpResponseBadRequest('Unknown team %s' % pk)

        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest('Invalid JSON: %s' % request.body)

        # We ignore everything except 'in_air'
        if 'in_air' in data:
            in_air = data['in_air']

            if in_air is not True and in_air is not False:
                return HttpResponseBadRequest('in_air must be boolean')

            currently_in_air = TakeoffOrLandingEvent.user_in_air(user)

            # New event only necessary if changing status
            if currently_in_air != in_air:
                event = TakeoffOrLandingEvent(user=user, uas_in_air=in_air)
                event.save()

        return HttpResponse(
            json.dumps(user_json(user)),
            content_type="application/json")
Пример #2
0
    def put(self, request, pk):
        """PUT allows updating in-air status."""
        try:
            user = User.objects.get(pk=int(pk))
        except User.DoesNotExist:
            return HttpResponseBadRequest('Unknown team %s' % pk)

        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest('Invalid JSON: %s' % request.body)

        # We ignore everything except 'in_air'
        if 'in_air' in data:
            in_air = data['in_air']

            if in_air is not True and in_air is not False:
                return HttpResponseBadRequest('in_air must be boolean')

            currently_in_air = TakeoffOrLandingEvent.user_in_air(user)

            # New event only necessary if changing status
            if currently_in_air != in_air:
                event = TakeoffOrLandingEvent(user=user, uas_in_air=in_air)
                event.save()

        return HttpResponse(json.dumps(user_json(user)),
                            content_type="application/json")
Пример #3
0
def user_json(user):
    """Generate JSON-style dict for user."""
    return {
        'name': user.username,
        'id': user.pk,
        'in_air': TakeoffOrLandingEvent.user_in_air(user),
        'active': UasTelemetry.user_active(user),
    }
    def test_user_in_air_second_flight(self):
        """In-air during second flight."""
        self.create_event(self.year2000, True)
        self.create_event(self.year2000 + self.ten_minutes, False)

        self.create_event(self.year2001, True)

        self.assertTrue(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #5
0
    def test_user_in_air_second_flight(self):
        """In-air during second flight."""
        self.create_event(self.year2000, True)
        self.create_event(self.year2000 + self.ten_minutes, False)

        self.create_event(self.year2001, True)

        self.assertTrue(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #6
0
def user_json(user):
    """Generate JSON-style dict for user."""
    return {
        'name': user.username,
        'id': user.pk,
        'in_air': TakeoffOrLandingEvent.user_in_air(user),
        'active': UasTelemetry.user_active(user),
    }
    def test_user_in_air_time(self):
        """In-air base time check."""
        self.create_event(self.year2000, True)
        self.create_event(self.year2000 + 2 * self.ten_minutes, False)

        time = self.year2000 + self.ten_minutes

        self.assertTrue(TakeoffOrLandingEvent.user_in_air(self.user1,
                                                          time=time))
Пример #8
0
    def test_user_in_air_time(self):
        """In-air base time check."""
        self.create_event(self.year2000, True)
        self.create_event(self.year2000 + 2 * self.ten_minutes, False)

        time = self.year2000 + self.ten_minutes

        self.assertTrue(
            TakeoffOrLandingEvent.user_in_air(self.user1, time=time))
Пример #9
0
def user_json(user):
    """Generate JSON-style dict for user."""
    return {
        'name': user.username,
        'id': user.pk,
        'on_clock': MissionClockEvent.user_on_clock(user),
        'on_timeout': MissionClockEvent.user_on_timeout(user),
        'in_air': TakeoffOrLandingEvent.user_in_air(user),
        'active': UasTelemetry.user_active(user),
    }
Пример #10
0
def user_json(user):
    """Generate JSON-style dict for user."""
    return {
        'name': user.username,
        'id': user.pk,
        'on_clock': MissionClockEvent.user_on_clock(user),
        'on_timeout': MissionClockEvent.user_on_timeout(user),
        'in_air': TakeoffOrLandingEvent.user_in_air(user),
        'active': UasTelemetry.user_active(user),
    }
Пример #11
0
    def put(self, request, pk):
        """PUT allows updating status."""
        try:
            user = User.objects.get(pk=int(pk))
        except User.DoesNotExist:
            return HttpResponseBadRequest('Unknown team %s' % pk)
        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest('Invalid JSON: %s' % request.body)

        # Potential events to update.
        takeoff_event = None
        clock_event = None
        # Update whether UAS is in air.
        if 'in_air' in data:
            in_air = data['in_air']
            if not isinstance(in_air, bool):
                return HttpResponseBadRequest('in_air must be boolean')

            currently_in_air = TakeoffOrLandingEvent.user_in_air(user)
            # New event only necessary if changing status
            if currently_in_air != in_air:
                takeoff_event = TakeoffOrLandingEvent(user=user,
                                                      uas_in_air=in_air)
        # Update whether UAS in on clock or timeout.
        if 'on_clock' in data or 'on_timeout' in data:
            currently_on_clock = MissionClockEvent.user_on_clock(user)

            currently_on_timeout = MissionClockEvent.user_on_timeout(user)
            on_clock = data.get('on_clock', currently_on_clock)
            on_timeout = data.get('on_timeout', currently_on_timeout)
            if (not isinstance(on_clock, bool) or
                    not isinstance(on_timeout, bool)):
                return HttpResponseBadRequest(
                    'on_clock and on_timeout must be boolean.')
            if on_clock and on_timeout:
                return HttpResponseBadRequest(
                    'Cannot be on mission clock and on timeout.')
            # New event only necessary if changing status
            if (on_clock != currently_on_clock or
                    on_timeout != currently_on_timeout):
                clock_event = MissionClockEvent(user=user,
                                                team_on_clock=on_clock,
                                                team_on_timeout=on_timeout)
        # Request was valid. Save updates.
        if takeoff_event:
            takeoff_event.save()
        if clock_event:
            clock_event.save()

        return HttpResponse(
            json.dumps(user_json(user)),
            content_type="application/json")
Пример #12
0
    def put(self, request, pk):
        """PUT allows updating status."""
        try:
            user = User.objects.get(pk=int(pk))
        except User.DoesNotExist:
            return HttpResponseBadRequest('Unknown team %s' % pk)
        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest('Invalid JSON: %s' % request.body)

        # Potential events to update.
        takeoff_event = None
        clock_event = None
        # Update whether UAS is in air.
        if 'in_air' in data:
            in_air = data['in_air']
            if not isinstance(in_air, bool):
                return HttpResponseBadRequest('in_air must be boolean')

            currently_in_air = TakeoffOrLandingEvent.user_in_air(user)
            # New event only necessary if changing status
            if currently_in_air != in_air:
                takeoff_event = TakeoffOrLandingEvent(user=user,
                                                      uas_in_air=in_air)
        # Update whether UAS in on clock or timeout.
        if 'on_clock' in data or 'on_timeout' in data:
            currently_on_clock = MissionClockEvent.user_on_clock(user)

            currently_on_timeout = MissionClockEvent.user_on_timeout(user)
            on_clock = data.get('on_clock', currently_on_clock)
            on_timeout = data.get('on_timeout', currently_on_timeout)
            if (not isinstance(on_clock, bool)
                    or not isinstance(on_timeout, bool)):
                return HttpResponseBadRequest(
                    'on_clock and on_timeout must be boolean.')
            if on_clock and on_timeout:
                return HttpResponseBadRequest(
                    'Cannot be on mission clock and on timeout.')
            # New event only necessary if changing status
            if (on_clock != currently_on_clock
                    or on_timeout != currently_on_timeout):
                clock_event = MissionClockEvent(user=user,
                                                team_on_clock=on_clock,
                                                team_on_timeout=on_timeout)
        # Request was valid. Save updates.
        if takeoff_event:
            takeoff_event.save()
        if clock_event:
            clock_event.save()

        return HttpResponse(json.dumps(user_json(user)),
                            content_type="application/json")
Пример #13
0
 def test_user_in_air_no_logs(self):
     """Not in-air without logs."""
     self.assertFalse(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #14
0
    def test_user_in_air_after_landing(self):
        """Not in-air after landing."""
        self.create_event(self.year2000, True)
        self.create_event(self.year2000 + self.ten_minutes, False)

        self.assertFalse(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #15
0
    def test_user_in_air_after_landing(self):
        """Not in-air after landing."""
        self.create_event(self.year2000, True)
        self.create_event(self.year2000 + self.ten_minutes, False)

        self.assertFalse(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #16
0
    def test_user_in_air_before_landing(self):
        """In-air before landing."""
        self.create_event(self.year2000, True)

        self.assertTrue(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #17
0
 def test_user_in_air_no_logs(self):
     """Not in-air without logs."""
     self.assertFalse(TakeoffOrLandingEvent.user_in_air(self.user1))
Пример #18
0
    def test_user_in_air_before_landing(self):
        """In-air before landing."""
        self.create_event(self.year2000, True)

        self.assertTrue(TakeoffOrLandingEvent.user_in_air(self.user1))