Exemple #1
0
    def get(self):
        cars = Car.select()
        query = []
        for car in cars:
            query.append(car.dictionary())

        return {'data': query, 'message': '', 'status': 'success'}
Exemple #2
0
    def get(self):
        # get request parameters
        parameters = request.args

        # extract parameters from request
        brand = parameters.get("brand", None)
        ext_color = parameters.get("extcolor", None)
        int_color = parameters.get("intcolor", None)
        year = parameters.get("year", None)
        transmission = parameters.get("trans", None)

        query = Car.select()  # select all cars

        # update query due to request parameters
        if brand is not None:
            query = query.where(Car.brand == brand)
        if ext_color is not None:
            query = query.where(Car.ext_color == ext_color)
        if int_color is not None:
            query = query.where(Car.int_color == int_color)
        if year is not None:
            query = query.where(Car.year == year)
        if transmission is not None:
            query = query.where(Car.transmission == transmission)

        # return list of desired cars as JSON Object
        return jsonify(list(query.dicts()))
Exemple #3
0
    def get(self):
        logger = logging.getLogger('app.get-car-')

        cars = [
            car.dictionary() for car in Car.select().where(Car.flagged == True)
        ]

        return {'data': cars, 'message': '', 'status': 'success'}
Exemple #4
0
    def get(self, car_type):
        print car_type
        cars = [
            car.dictionary()
            for car in Car.select().where((Car.car_type == car_type)
                                          & (Car.published == True))
        ]

        if cars:
            return {'data': cars, 'message': '', 'status': 'success'}
        else:
            return {'data': '', 'message': '', 'status': 'error'}
Exemple #5
0
    def get(self):
        cars = [
            car.dictionary()
            for car in Car.select().where((Car.featured == True)
                                          & (Car.published == True)
                                          & (Car.flagged == False))
        ]

        if cars:
            return {'data': cars, 'message': '', 'status': 'succes'}
        else:
            return {
                'data': '',
                'message': 'No featured cars at the moment',
                'status': 'error'
            }
Exemple #6
0
 def get(self, user):
     try:
         cars = [
             car.dictionary() for car in Car.select().where(
                 Car.owner == int(user)).join(User)
         ]
         if cars:
             return {'data': cars, 'message': '', 'status': 'success'}
         else:
             return {
                 'data': '',
                 'message': 'User has not cars',
                 'status': 'error'
             }
     except Exception as e:
         print str(e)
         return {
             'data': '',
             'message': 'An error occur pls contact admin',
             'status': 'error'
         }
Exemple #7
0
 def get(self):
     user = User.get(id=int(get_jwt_identity()))
     if user.account_type != 'admin':
         return {}, 401
     cars = [car.dictionary() for car in Car.select()]
     return {'data': cars, 'message': '', 'status': 'success'}