예제 #1
0
    def post(request):

        try:
            if PromoModel.objects.filter(name=request.POST[consts.PARAM_PROMO_CODE]).exists():
                sess_id = request.POST[consts.PARAM_SESSION_ID]
                user = SessionModel.get_user_by_session(sess_id)
                selected_promo = PromoModel.objects.get(name=request.POST[consts.PARAM_PROMO_CODE])
                if UserPromoModel.objects.filter(user=user, promo=selected_promo).exists():
                    response = common_response.CommonResponse(success=False,
                                                              reason='Promo Code Already Used',
                                                              error_code=consts.ERROR_USED_PROMO)
                    return HttpResponse(response.respond(), content_type="application/json")
                else:
                    new_user_promo = UserPromoModel(user=user,
                                                    promo=selected_promo,
                                                    remaining_ride=selected_promo.maximum_number_of_discount)
                    new_user_promo.save()
                    response = common_response.CommonResponse(success=True,
                                                              reason='Promo Successfully Added',
                                                              error_code=consts.ERROR_NONE)
                    return HttpResponse(response.respond(), content_type="application/json")
            else:
                response = common_response.CommonResponse(success=False,
                                                          reason='Incorrect Promo',
                                                          error_code=consts.ERROR_INCORRECT_PROMO)
                return HttpResponse(response.respond(), content_type="application/json")
        except:
            response = common_response.CommonResponse(success=False,
                                                      reason='Incorrect Parameters',
                                                      error_code=consts.ERROR_INCORRECT_PARAMETERS)
            return HttpResponse(response.respond(), content_type="application/json")
예제 #2
0
 def post(request):
     try:
         sess_id = request.POST[consts.PARAM_SESSION_ID]
         user = SessionModel.get_user_by_session(sess_id)
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='Invalid Session',
             error_code=consts.ERROR_INCORRECT_SESSION)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     try:
         this_order = RideModel.objects.get(
             ride_id=request.POST[consts.PARAM_ORDER_ID])
         order_driver = SessionModel.objects.get(
             user=this_order.driver.user)
         trip_data = {
             'trip_status': this_order.order_status,
             'driver_lat': str(order_driver.current_lat),
             'driver_lon': str(order_driver.current_lon)
         }
         response = common_response.CommonResponse(
             success=True,
             reason='New Order',
             data=trip_data,
             error_code=consts.ERROR_NONE)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='Incorrect Order',
             error_code=consts.ERROR_INCORRECT_RIDE_ID)
         return HttpResponse(response.respond(),
                             content_type="application/json")
예제 #3
0
    def post(request):

        try:
            name = request.POST[consts.PARAM_PROMO_CODE]
            vehicle_type = request.POST[consts.PARAM_VEHICLE_TYPE]
            maximum_number_of_discount = request.POST[consts.PARAM_PROMO_NUMBER_OF_RIDE]
            discount = request.POST[consts.PARAM_PROMO_AMOUNT_OF_DISCOUNT]

            if PromoModel.objects.filter(vehicle_type=VehicleClassModel.objects.get(pk=vehicle_type)).exists():
                response = common_response.CommonResponse(success=False,
                                                          reason='Promo Ongoing Already',
                                                          error_code=consts.ERROR_ONGOING_PROMO)
                return HttpResponse(response.respond(), content_type="application/json")
            else:
                new_promo = PromoModel(name=name,
                                       vehicle_type=VehicleClassModel.objects.get(pk=vehicle_type),
                                       maximum_number_of_discount=maximum_number_of_discount,
                                       discount=discount)
                new_promo.save()
                response = common_response.CommonResponse(success=True,
                                                          reason='New Promo Added',
                                                          error_code=consts.ERROR_NONE)
                return HttpResponse(response.respond(), content_type="application/json")
        except:
            response = common_response.CommonResponse(success=False,
                                                      reason='Incorrect Parameters',
                                                      error_code=consts.ERROR_INCORRECT_PARAMETERS)
            return HttpResponse(response.respond(), content_type="application/json")
예제 #4
0
    def post(request):
        try:
            sess_id = request.POST[consts.PARAM_SESSION_ID]
            user_session = SessionModel.objects.get(session_id=sess_id)
            driver_status = request.POST[consts.PARAM_DRIVER_STATUS]
            if driver_status == 'online':
                user_session.driver_status = consts.STATUS_DRIVER_ONLINE
                user_session.save()
            if driver_status == 'offline':
                user_session.driver_status = consts.STATUS_DRIVER_OFFLINE
                user_session.save()

            response = common_response.CommonResponse(
                success=True,
                reason='Status Successfully Updated',
                error_code=consts.ERROR_NONE)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Session',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")
예제 #5
0
 def post(request):
     try:
         sess_id = request.POST[consts.PARAM_SESSION_ID]
         user = SessionModel.get_user_by_session(sess_id)
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='Invalid Session',
             error_code=consts.ERROR_INCORRECT_SESSION)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     try:
         driver = DriverModel.objects.get(user=user)
         vehicle_class = VehicleClassModel.objects.get(
             pk=request.POST[consts.PARAM_VEHICLE_TYPE_ID])
         new_vehicle = VehicleModel(
             registration_number=request.POST[consts.PARAM_VEHICLE_NUMBER],
             color=request.POST[consts.PARAM_VEHICLE_COLOR],
             model=request.POST[consts.PARAM_VEHICLE_NAME],
             ride_class=vehicle_class,
             driver=driver)
         new_vehicle.save()
         response = common_response.CommonResponse(
             success=True,
             reason='Vehicle Successfully Added',
             error_code=consts.ERROR_NONE)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='Incorrect Parameters',
             error_code=consts.ERROR_INCORRECT_PARAMETERS)
         return HttpResponse(response.respond(),
                             content_type="application/json")
예제 #6
0
    def post(request):
        try:
            sess_id = request.POST[consts.PARAM_SESSION_ID]
            user = SessionModel.get_user_by_session(sess_id)
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Session',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        try:
            driver = DriverModel(
                user=user,
                national_id=request.POST[consts.PARAM_DRIVER_LICENSE],
                driving_license=request.POST[consts.PARAM_DRIVER_LICENSE])

            driver.save()
            response = common_response.CommonResponse(
                success=True,
                reason='Driver Profile Successfully Added',
                error_code=consts.ERROR_NONE)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Session',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")
예제 #7
0
    def post(request):
        try:
            sess_id = request.POST[consts.PARAM_SESSION_ID]
            user = SessionModel.get_user_by_session(sess_id)
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Session',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        if SessionModel.objects.filter(
                session_id=request.POST[consts.PARAM_SESSION_ID],
                driver_status=consts.STATUS_DRIVER_APPROACHING_PICKUP).exisits(
                ):
            try:
                ride_id = request.POST[consts.PARAM_ORDER_ID]
                drop_lat = request.POST[consts.PARAM_LAT_TO]
                drop_lon = request.POST[consts.PARAM_LNG_TO]
            except:
                response = common_response.CommonResponse(
                    success=False,
                    reason='Incorrect Parameters',
                    error_code=consts.ERROR_INCORRECT_PARAMETERS)
                return HttpResponse(response.respond(),
                                    content_type="application/json")

            try:
                selected_trip = RideModel.objects.get(ride_id=ride_id)
                selected_trip.drop_lat = drop_lat
                selected_trip.drop_lon = drop_lon
                selected_trip.order_status = consts.STATUS_ORDER_COMPLETED
                selected_trip.save()
                driver_session = SessionModel.objects.get(user=user)
                driver_session.driver_status = consts.STATUS_DRIVER_ONLINE
                driver_session.save()
                response = common_response.CommonResponse(
                    success=True,
                    reason='Ride Successfully Started',
                    error_code=consts.ERROR_NONE)
                return HttpResponse(response.respond(),
                                    content_type="application/json")
            except:
                response = common_response.CommonResponse(
                    success=False,
                    reason='Incorrect Ride Information',
                    error_code=consts.ERROR_INCORRECT_RIDE_ID)
                return HttpResponse(response.respond(),
                                    content_type="application/json")
        else:
            response = common_response.CommonResponse(
                success=False,
                reason='Driver Can Not Start Ride',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")
예제 #8
0
    def post(request):

        try:
            sess_id = request.POST[consts.PARAM_SESSION_ID]
            user = SessionModel.get_user_by_session(sess_id)
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Session',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        try:
            all_ride_type = VehicleClassModel.objects.all()
            all_ride_type_array = []

            for ride_type in all_ride_type:
                discount = 0
                if PromoModel.objects.filter(vehicle_type=ride_type).exists():
                    for on_going_promo in PromoModel.objects.filter(
                            vehicle_type=ride_type):
                        if on_going_promo.promo_active and \
                                UserPromoModel.objects.filter(promo=on_going_promo, user=user).exists():
                            if UserPromoModel.objects.filter(
                                    promo=on_going_promo,
                                    user=user)[0].remaining_ride > 0:
                                discount = on_going_promo.discount
                one_ride = {
                    'vehicle_type': ride_type.id,
                    'type': ride_type.name,
                    'base_fare': ride_type.base_fare,
                    'per_kilometer_fare': ride_type.per_kilometer_fare,
                    'per_minute_fare': ride_type.per_minute_fare,
                    'maximum_passenger': ride_type.maximum_passenger,
                    'discount': discount
                }
                all_ride_type_array.append(one_ride)
            response = common_response.CommonResponse(
                success=True,
                reason='All Type of Rides',
                data=all_ride_type_array,
                error_code=consts.ERROR_NONE)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Incorrect Parameters',
                error_code=consts.ERROR_INCORRECT_PARAMETERS)
            return HttpResponse(response.respond(),
                                content_type="application/json")
예제 #9
0
    def post(request):
        response = UpdateLocationResponse()
        try:
            sess_id = request.POST[consts.PARAM_SESSION_ID]
            curr_lat = request.POST[consts.PARAM_LATITUDE]
            curr_lng = request.POST[consts.PARAM_LONGITUDE]
        except:
            print request.POST
            print "Required parameter exception"

        try:
            sess = SessionModel.get_session_by_id(sess_id)
            print sess.current_lat
            sess.current_lat = curr_lat
            sess.current_lon = curr_lng
            sess.save()

            response.set_status(UpdateLocationResponse.STATE_SUCCESS)
        except:
            print "User save error"

        response = common_response.CommonResponse(
            success=True,
            reason='Location Successfully Added',
            error_code=consts.ERROR_NONE)
        return HttpResponse(response.respond(),
                            content_type="application/json")
예제 #10
0
 def post(request):
     all_vehicle_type = VehicleClassModel.objects.all()
     all_vehicle_type_array = []
     for one_vehicle_type in all_vehicle_type:
         one_vehicle = {
             'vehicle_type': one_vehicle_type.name,
             'vehicle_type_id': one_vehicle_type.pk
         }
         all_vehicle_type_array.append(one_vehicle)
     response = common_response.CommonResponse(
         success=True,
         data=all_vehicle_type_array,
         reason='All Vehicle Type List',
         error_code=consts.ERROR_NONE)
     return HttpResponse(response.respond(),
                         content_type="application/json")
예제 #11
0
 def post(request):
     all_users = UserModel.objects.all()
     user_array = []
     for one_user in all_users:
         one_user_info = {
             'user name': one_user.username,
             'phone': one_user.phone,
             'user_type': one_user.user_type,
             'is_active': one_user.is_active,
             'pin': one_user.pin
         }
         user_array.append(one_user_info)
     response = common_response.CommonResponse(
         success=True,
         reason='ALL USERS',
         error_code=consts.ERROR_USER_PRESENT,
         data=user_array)
     # print(response)
     return HttpResponse(response.respond(),
                         content_type="application/json")
예제 #12
0
 def post(request):
     all_sessions = SessionModel.objects.all()
     user_array = []
     for one_session in all_sessions:
         one_user_info = {
             'username': one_session.user.username,
             'phone': one_session.user.phone,
             'session_id': one_session.session_id,
             'current_lat': str(one_session.current_lat),
             'current_lon': str(one_session.current_lon),
             'current_ride': one_session.current_ride,
             'is_driver': one_session.is_driver,
             'driver_status': one_session.driver_status
         }
         user_array.append(one_user_info)
     response = common_response.CommonResponse(
         success=True,
         reason='ALL SESSIONS',
         error_code=consts.ERROR_USER_PRESENT,
         data=user_array)
     # print(response)
     return HttpResponse(response.respond(),
                         content_type="application/json")
예제 #13
0
 def post(request):
     try:
         sess_id = request.POST[consts.PARAM_SESSION_ID]
         user = SessionModel.get_user_by_session(sess_id)
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='Invalid Session',
             error_code=consts.ERROR_INCORRECT_SESSION)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     try:
         curr_lat = request.POST[consts.PARAM_LATITUDE]
         curr_lng = request.POST[consts.PARAM_LONGITUDE]
         sess = SessionModel.get_session_by_id(sess_id)
         sess.current_lat = curr_lat
         sess.current_lon = curr_lng
         sess.save()
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='Incorrect Parameters',
             error_code=consts.ERROR_INCORRECT_PARAMETERS)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     try:
         driver_profile = DriverModel.objects.get(user=user)
     except:
         response = common_response.CommonResponse(
             success=False,
             reason='User Not Driver',
             error_code=consts.ERROR_USER_NOT_DRIVER)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     if RideModel.objects.filter(
             driver=driver_profile,
             order_status=consts.STATUS_ORDER_CONFIRMED).exists():
         current_trip = RideModel.objects.filter(
             driver=driver_profile,
             order_status=consts.STATUS_ORDER_CONFIRMED)[0]
         trip_data = {
             'ride_id': current_trip.ride_id,
             'user_name': current_trip.user.username,
             'user_phone': current_trip.user.phone,
             'user_rating': current_trip.user.average_rating,
             'pickup_lat': str(current_trip.pickup_lat),
             'pickup_lon': str(current_trip.pickup_lon),
             'drop_lat': str(current_trip.drop_lat),
             'drop_lon': str(current_trip.drop_lon)
         }
         response = common_response.CommonResponse(
             success=True,
             reason='New Order',
             data=trip_data,
             error_code=consts.ERROR_NONE)
         return HttpResponse(response.respond(),
                             content_type="application/json")
     else:
         response = common_response.CommonResponse(
             success=True,
             reason='No Ride Assigned',
             error_code=consts.ERROR_UNKNOWN)
         return HttpResponse(response.respond(),
                             content_type="application/json")
예제 #14
0
    def post(request):
        print request.POST
        try:
            sess_id = request.POST[consts.PARAM_SESSION_ID]
            user = SessionModel.get_user_by_session(sess_id)
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Session',
                error_code=consts.ERROR_INCORRECT_SESSION)
            return HttpResponse(response.respond(),
                                content_type="application/json")

        try:
            vehicle_class = VehicleClassModel.objects.get(
                pk=request.POST[consts.PARAM_VEHICLE_TYPE])
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Invalid Vehicle Type',
                error_code=consts.ERROR_INCORRECT_VEHICLE_TYPE)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        try:
            if RideModel.objects.filter(user=user,
                                        order_status__lte=2).exists():
                previous_incomplete_ride = RideModel.objects.filter(
                    user=user, order_status__lte=2)[0]
                driver_information = {
                    'driver_name':
                    previous_incomplete_ride.driver.user.username,
                    'driver_phone': previous_incomplete_ride.driver.user.phone
                    # 'driver_rating': selected_driver.driver_profile.average_rating,
                    # 'driver_trip_count': selected_driver.driver_profile.number_of_rides
                }
                vehicle_information = {
                    # 'model': selected_driver.current_vehicle.model,
                    # 'registration_number': selected_driver.current_vehicle.registration_number
                }

                order_data = {
                    'trip_order_id': previous_incomplete_ride.ride_id,
                    'driver_information': driver_information,
                    'vehicle_information': vehicle_information
                }
                response = common_response.CommonResponse(
                    success=True,
                    reason='Order Data Retrieved',
                    data=order_data,
                    error_code=consts.ERROR_NONE)
                return HttpResponse(response.respond(),
                                    content_type="application/json")
            else:
                print "Finding new ride"
                new_order = RideModel(
                    user=user,
                    vehicle_class=vehicle_class,
                    pickup_lat=request.POST[consts.PARAM_LAT_FROM],
                    pickup_lon=request.POST[consts.PARAM_LNG_FROM],
                    drop_lat=request.POST[consts.PARAM_LAT_TO],
                    drop_lon=request.POST[consts.PARAM_LNG_FROM],
                    order_status=consts.STATUS_ORDER_PLACED)
                new_order.save()
                print "Finding Drivers"
                selected_driver = SearchRide.find_driver(
                    request.POST[consts.PARAM_LAT_FROM],
                    request.POST[consts.PARAM_LNG_FROM])
                if selected_driver is None:
                    new_order.order_status = consts.STATUS_ORDER_NO_DRIVER_FOUND
                    new_order.save()
                    response = common_response.CommonResponse(
                        success=False,
                        reason='No Driver Found',
                        error_code=consts.ERROR_NO_DRIVER_FOUND)
                    return HttpResponse(response.respond(),
                                        content_type="application/json")
                else:
                    print()
                    new_order.driver = selected_driver.driver_profile
                    # new_order.vehicle = selected_driver.current_vehicle
                    new_order.order_status = consts.STATUS_ORDER_CONFIRMED
                    new_order.save()
                    selected_driver.driver_status = consts.STATUS_DRIVER_APPROACHING_PICKUP
                    selected_driver.save()
                    driver_information = {
                        'driver_name': selected_driver.user.username,
                        'driver_phone': selected_driver.user.phone
                        # 'driver_rating': selected_driver.driver_profile.average_rating,
                        # 'driver_trip_count': selected_driver.driver_profile.number_of_rides
                    }
                    vehicle_information = {
                        # 'model': selected_driver.current_vehicle.model,
                        # 'registration_number': selected_driver.current_vehicle.registration_number
                    }

                    order_data = {
                        'trip_order_id': new_order.ride_id,
                        'driver_information': driver_information,
                        'vehicle_information': vehicle_information
                    }
                    response = common_response.CommonResponse(
                        success=True,
                        reason='Order Successfully Received',
                        data=order_data,
                        error_code=consts.ERROR_NONE)
                    return HttpResponse(response.respond(),
                                        content_type="application/json")
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Incorrect Parameters',
                error_code=consts.ERROR_INCORRECT_PARAMETERS)
            return HttpResponse(response.respond(),
                                content_type="application/json")
예제 #15
0
    def post(request):
        phone = None
        password = None
        try:
            phone = request.POST[consts.PARAM_PHONE]
            password = request.POST[consts.PARAM_PASSWORD]
            '''mention the app type[driver ]'''
            app_type = request.POST[consts.PARAM_APP_TYPE]
            user = UserModel.get_user_by_phone_password(phone, password)
            if user is not None:
                if app_type == 'driver':
                    is_driver = True
                else:
                    is_driver = False
                if SessionModel.objects.filter(user=user).exists():
                    existing_sessions = SessionModel.objects.filter(user=user)
                    for existing_session in existing_sessions:
                        existing_session.delete()

                session = SessionModel(user=user, is_driver=is_driver)
                session.save()
                if is_driver:
                    if DriverModel.objects.filter(user=user).exists():
                        driver = DriverModel.objects.get(user=user)
                        session.driver_profile = driver
                        session.save()
                        if VehicleModel.objects.filter(driver=driver).exists():
                            driver_data = {
                                'driver_nid': driver.national_id,
                                'driver_dl': driver.driving_license,
                                'driver_rating': driver.average_rating,
                                'driver_ride_count': driver.number_of_rides
                            }
                            all_vehicles = VehicleModel.objects.filter(
                                driver=driver)
                            vehicle_array = []
                            for one_vehicle in all_vehicles:
                                vehicle_data = {
                                    'registration_number':
                                    one_vehicle.registration_number,
                                    'vehicle_type':
                                    one_vehicle.ride_class.name,
                                    'vehicle_type_id':
                                    one_vehicle.ride_class.pk,
                                    'vehicle_color': one_vehicle.color
                                }
                                vehicle_array.append(vehicle_data)
                            user_data = {
                                'session_id': session.session_id,
                                'user_name': session.user.username,
                                'user_email': session.user.email,
                                'user_rating': session.user.average_rating,
                                'user_phone': session.user.phone,
                                'user_photo_url':
                                str(session.user.user_picture),
                                'driver': driver_data,
                                'vehicle': vehicle_array
                            }
                            session.driver_status = consts.STATUS_DRIVER_ONLINE
                            session.driver_profile = driver
                            session.save()
                            response = common_response.CommonResponse(
                                success=True,
                                data=user_data,
                                error_code=consts.ERROR_NONE)
                            return HttpResponse(
                                response.respond(),
                                content_type="application/json")
                        else:
                            driver_data = {
                                'driver_nid': driver.national_id,
                                'driver_dl': driver.driving_license,
                                'driver_rating': driver.average_rating,
                                'driver_ride_count': driver.number_of_rides
                            }
                            user_data = {
                                'session_id': session.session_id,
                                'user_name': session.user.username,
                                'user_email': session.user.email,
                                'user_rating': session.user.average_rating,
                                'user_phone': session.user.phone,
                                'user_photo_url':
                                str(session.user.user_picture),
                                'driver': driver_data,
                                'vehicle': None
                            }
                            session.driver_profile = driver
                            session.driver_status = consts.STATUS_DRIVER_OFFLINE
                            session.save()
                            response = common_response.CommonResponse(
                                success=True,
                                data=user_data,
                                reason='Vehicle Not Selected',
                                error_code=consts.ERROR_NONE)
                            return HttpResponse(
                                response.respond(),
                                content_type="application/json")
                    else:
                        user_data = {
                            'session_id': session.session_id,
                            'user_name': session.user.username,
                            'user_email': session.user.email,
                            'user_rating': session.user.average_rating,
                            'user_phone': session.user.phone,
                            'user_photo_url': str(session.user.user_picture),
                            'driver': None,
                            'vehicle': None
                        }
                        session.driver_status = consts.STATUS_DRIVER_OFFLINE
                        session.save()
                        response = common_response.CommonResponse(
                            success=True,
                            data=user_data,
                            reason='Driver Profile Not Added',
                            error_code=consts.ERROR_NONE)
                        return HttpResponse(response.respond(),
                                            content_type="application/json")
                else:
                    user_data = {
                        'session_id': session.session_id,
                        'user_name': session.user.username,
                        'user_email': session.user.email,
                        'user_rating': session.user.average_rating,
                        'user_phone': session.user.phone,
                        'user_photo_url': str(session.user.user_picture)
                    }
                    session.driver_status = consts.STATUS_NOT_DRIVER
                    session.save()
                    response = common_response.CommonResponse(
                        success=True,
                        data=user_data,
                        error_code=consts.ERROR_NONE)
                    return HttpResponse(response.respond(),
                                        content_type="application/json")
            else:
                response = common_response.CommonResponse(
                    success=False,
                    reason='Incorrect Phone Number or Password',
                    error_code=consts.ERROR_INCORRECT_PHONE_OR_PASSWORD)
                return HttpResponse(response.respond(),
                                    content_type="application/json")
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Incorrect Parameters',
                error_code=consts.ERROR_INCORRECT_PARAMETERS)
            return HttpResponse(response.respond(),
                                content_type="application/json")
예제 #16
0
    def post(request):
        print request.POST
        optional = True
        user_type = None
        try:
            phone = request.POST[consts.PARAM_PHONE]
            name = request.POST[consts.PARAM_USER_NAME]
            password = request.POST[consts.PARAM_PASSWORD]

            if consts.PARAM_APP_TYPE in request.POST:
                app_type = request.POST[consts.PARAM_APP_TYPE]
            else:
                app_type = 'user'

            if consts.PARAM_USER_MAIL in request.POST:
                email = request.POST[consts.PARAM_USER_MAIL]
            else:
                email = ''

            if consts.PARAM_USER_ADDRESS in request.POST:
                address = request.POST[consts.PARAM_USER_ADDRESS]
            else:
                address = ''

            if app_type == 'driver':
                user_type = 2
            else:
                user_type = 1
            if UserModel.objects.filter(phone=phone).exists():
                response = common_response.CommonResponse(
                    success=False,
                    reason='Phone Number Already Registered',
                    error_code=consts.ERROR_USER_PRESENT)
                return HttpResponse(response.respond(),
                                    content_type="application/json")
            else:
                user = UserModel(username=name,
                                 email=email,
                                 phone=phone,
                                 password=UserModel.encrypt_password(password),
                                 address=address,
                                 user_type=user_type,
                                 is_active=True)
                user.save()

            if consts.PARAM_USER_PIC in request.FILES:
                user.user_picture = request.FILES[consts.PARAM_USER_PIC]
                user.save()
            """
            for pin
            """
            # pin = str(randint(1001, 9999))
            # user.pin = pin
            # user.save()
            #
            # #todo add sms api to send user the pin for account verification
            """
            for pin
            """

            response = common_response.CommonResponse(
                success=True, error_code=consts.ERROR_NONE)
            return HttpResponse(response.respond(),
                                content_type="application/json")
        except:
            response = common_response.CommonResponse(
                success=False,
                reason='Incorrect Parameters',
                error_code=consts.ERROR_INCORRECT_PARAMETERS)
            return HttpResponse(response.respond(),
                                content_type="application/json")