Exemplo n.º 1
0
    def post(self, request, number):
            car = get_model_or_404(Car, number=number)

            stop_number = get_key_or_400(request.POST, 'stop_number')
            stop = get_model_or_404(Stop, number=stop_number)

            userprofile = self.user.get_profile()
            userprofile.check_in(car, stop)
            return {'status': 'ok'}
Exemplo n.º 2
0
    def post(self, request, number):
        car = get_model_or_404(Car, number=number)

        stop_number = get_key_or_400(request.POST, 'stop_number')
        stop = get_model_or_404(Stop, number=stop_number)

        userprofile = self.user.get_profile()
        userprofile.check_in(car, stop)
        return {'status': 'ok'}
Exemplo n.º 3
0
    def get(self, request, number):
        model = self.resource.model
        model_instance = get_model_or_404(model, number=number)

        #Only the car's owner can view detailed information
        if not model_instance.owner == self.user.get_profile():
            raise ErrorResponse(403, {'detail': 'You do not own this car'})
        return model_instance
Exemplo n.º 4
0
    def get(self, request, number):
        model = self.resource.model
        model_instance = get_model_or_404(model, number=number)

        #Only the car's owner can view detailed information
        if not model_instance.owner == self.user.get_profile():
            raise ErrorResponse(403, {'detail': 'You do not own this car'})
        return model_instance
Exemplo n.º 5
0
    def post(self, request, number):
        car = get_model_or_404(Car, number=number)

        try:
           # import pdb; pdb.set_trace()
            car.buy_back(self.user)
        except Car.NotAllowedException:
            raise ErrorResponse(403,
                {'detail': 'This car does not belong to you'})
        else:
            return {'status': 'ok'}
Exemplo n.º 6
0
    def post(self, request, number):
        car = get_model_or_404(Car, number=number)

        try:
            # import pdb; pdb.set_trace()
            car.buy_back(self.user)
        except Car.NotAllowedException:
            raise ErrorResponse(403,
                                {'detail': 'This car does not belong to you'})
        else:
            return {'status': 'ok'}
Exemplo n.º 7
0
    def post(self, request, number):
        car = get_model_or_404(Car, number=number)

        try:
            car.sell_to(self.user)
        except Car.NotAllowedException:
            raise ErrorResponse(403,
                {'detail': 'You are not allowed to purchase this car'})
        except UserProfile.InsufficientFundsException:
            raise ErrorResponse(403, {'detail': 'You cannot afford this car'})
        else:
            return {'status': 'ok'}
Exemplo n.º 8
0
    def post(self, request, number):
        car = get_model_or_404(Car, number=number)

        try:
            car.sell_to(self.user)
        except Car.NotAllowedException:
            raise ErrorResponse(
                403, {'detail': 'You are not allowed to purchase this car'})
        except UserProfile.InsufficientFundsException:
            raise ErrorResponse(403, {'detail': 'You cannot afford this car'})
        else:
            return {'status': 'ok'}
Exemplo n.º 9
0
    def get(self, request, number):
        car = get_model_or_404(Car, number=number)

        for event in Event.objects.get_car_timeline(car):
            if event.event == 'car_ride':
                user = event.data.get('rider')
            else:
                user = event.data.get('user')

            if user:
                yield {'user': user.username,
                       'event': event.event,
                       'date': event.date}
Exemplo n.º 10
0
    def get(self, request, number):
        car = get_model_or_404(Car, number=number)

        for event in Event.objects.get_car_timeline(car):
            if event.event == 'car_ride':
                user = event.data.get('rider')
            else:
                user = event.data.get('user')

            if user:
                yield {
                    'user': user.username,
                    'event': event.event,
                    'date': event.date
                }
Exemplo n.º 11
0
 def post(self, request):
     stop_number = get_key_or_400(request.POST, 'stop_number')
     stop = get_model_or_404(Stop, number=stop_number)
     try:
         profile = self.user.get_profile()
         if profile.riding:
             car = profile.riding.car
         fare = self.user.get_profile().check_out(stop)
         dic = {'fare': fare}
         if get_rule('RULE_CAN_BUY_CAR', self.user, car):
             dic['purchase'] = {
                 'price': get_rule('RULE_GET_STREETCAR_PRICE',
                                   self.user,
                                   car),
                 'url': reverse('car-sell', args=(car.number,))}
         return dic
     except UserProfile.NotCheckedInException:
         raise ErrorResponse(400, {'detail': 'User is not checked in'})
Exemplo n.º 12
0
 def post(self, request):
     stop_number = get_key_or_400(request.POST, 'stop_number')
     stop = get_model_or_404(Stop, number=stop_number)
     try:
         profile = self.user.get_profile()
         if profile.riding:
             car = profile.riding.car
         fare = self.user.get_profile().check_out(stop)
         dic = {'fare': fare}
         if get_rule('RULE_CAN_BUY_CAR', self.user, car):
             dic['purchase'] = {
                 'price': get_rule('RULE_GET_STREETCAR_PRICE', self.user,
                                   car),
                 'url': reverse('car-sell', args=(car.number, ))
             }
         return dic
     except UserProfile.NotCheckedInException:
         raise ErrorResponse(400, {'detail': 'User is not checked in'})
Exemplo n.º 13
0
    def get(self, request, number):
        stop = get_model_or_404(Stop, number=number)
        dic = dict()
        for field in self.fields:
            dic[field] = getattr(stop, field)

        if self.user.get_profile().riding != None:
            dic['checkout_url'] = reverse('car-checkout')
        else:
            dic['cars_nearby'] = []
            limit = settings.CAR_SEARCH_LIMIT
            checked_in = self.user.get_profile().riding != None
            for car in Car.objects.find_nearby(stop)[:limit]:
                car_dic = {'number': car.number,
                          'location': car.location,
                          'checkin_url': reverse('car-checkin',
                                                 args=(car.number,))}
                dic['cars_nearby'].append(car_dic)

        return dic