def update(self, request, trip_id=None, username=None):
        data = request.data
        current_user = rest.utils.get_rest_user(request)
        try:
            trip = server.models.Trip.objects.get(id=trip_id)
            status = data['status']
            person_participation = trip.get_participations().filter(author__username=username).get()
            person = person_participation.author

            if current_user != person and current_user != trip.author:
            # only the author of the trip or the owner of the
            # participation can manipulate here
                return piston.utils.rc.FORBIDDEN

            status_code = person_participation.get_status_code(status)

            if status_code < person_participation.get_status_code():
                result = server.models.Response(
                        server.models.Response.FORBIDDEN,
                        'Message',
                         'Can not fall back from '+str(data['status'])+'to ' +str(status)+ 'status at this point')
                return rest.utils.extract_result_from_response(result)

            status_set = server.models.Participation._status

            if status == status_set['accept'][0]:
                if not current_user == trip.author:
                    # this is a status that can be set just by the driver
                    return piston.utils.rc.FORBIDDEN
                result = server.driver.acceptRide(trip, current_user, person_participation.author)
            elif status == status_set['start'][0]:
                result = server.passenger.startRide(trip, person_participation.author)
            elif status == status_set['finish'][0]:
                result = server.passenger.finishRide(trip, person_participation.author)
            else:
                result = server.models.Response(
                        server.models.Response.FORBIDDEN,
                        'Message',
                         'Can not fall back from '+str(data['status'])+'to ' +str(status)+ 'status at this point')
            return rest.utils.extract_result_from_response(result)


        except server.models.Trip.DoesNotExist:
            return piston.utils.rc.NOT_FOUND
        except server.models.Participation.DoesNotExist:
            return piston.utils.rc.NOT_FOUND
        except KeyError, e:
            result = server.models.Response(
                    server.models.Response.BAD_REQUEST,
                    'Message',
                     e)

            return rest.utils.extract_result_from_response(result)
dataset/ETHPy150Open dgraziotin/dycapo/rest/wrappers/participation.py/ParticipationHandler.update/original