コード例 #1
0
def get_client(client_id):
    """
    Get Single Client
    :param client_id:
    :return:
    """
    if bson.objectid.ObjectId.is_valid(client_id):
        client = ClientDocument.objects(id=client_id).first()
        if client:
            return Response(data=ClientSchema(many=False).dump(client).data).send()
        return Response(message='No Client Found With The Given ID', status_code=404).send()
    return Response(message='Invalid Client Id Given.', status_code=403).send()
コード例 #2
0
 def create_user(self, request, **kwargs):
     '''To create a new user'''
     return Response(
         accounts_services.create_new_user(data=request.data),
         status=status.HTTP_201_CREATED,
         message='User Account Created Successfully.'
     )
コード例 #3
0
def get_clients():
    """
    Get Client List With Pagination
    :return:
    """
    data = DataTable(document=ClientDocument, schema=ClientSchema).get_data
    return Response(data=data).send()
コード例 #4
0
 def send_reservation_email(self, request, **kwargs):
     '''
     get:
     Retrieve Reservation Information and Sent them to email
     '''
     return Response(reservation_services.send_reservation_email(
         request.user, kwargs.get('pk')),
                     message='Email Sent!.')
コード例 #5
0
    def reservations(self, request, **kwargs):
        '''
        get:
        Retrieve Reservation information for flight

        post:
        Make reservation for flight
        '''
        if request.method == 'GET':
            return Response(
                reservation_services.filter_flight_reservations(
                    request.user, kwargs.get('pk')))
        if request.method == 'POST':
            return Response(reservation_services.make_flight_reservation(
                request.user, flight_pk=kwargs.get('pk'), data=request.data),
                            status=status.HTTP_201_CREATED,
                            message='Reservation made Successfully.')
コード例 #6
0
 def retrieve(self, request, **kwargs):
     '''
     get:
     Retrieve Single Flight Information
     '''
     return Response(
         reservation_services.retrieve_flight(request.user,
                                              kwargs.get('pk')))
コード例 #7
0
 def list(self, request, **kwargs):
     '''
     get:
     List/Filter Flights extra queries: from, destination, date
     '''
     return Response(
         reservation_services.filter_flights(
             request.user, query_params=request.query_params))
コード例 #8
0
 def list(self, request, **kwargs):
     airlines = reservation_services.filter_airlines(
         request.user,
         request.query_params,
     )
     return Response(
         paginate(request=request,
                  query_set=airlines,
                  serializer=reservation_serializers.AirlineSerializer))
コード例 #9
0
 def create(self, request, **kwargs):
     '''
     post:
     Create Single Reservation (Book Reservation)
     '''
     return Response(reservation_services.make_own_reservation(
         request.user, data=request.data),
                     status=status.HTTP_201_CREATED,
                     message='Reservation made Successfully.')
コード例 #10
0
def login():
    user = check_authentication()
    time.sleep(5)

    if user is not False:
        session = set_current_session(user)
        if session:
            sess = SessionSchema(many=False).dump(session).data
            return Response(data=sess, message='Signed In Successfully').send()
        else:
            return Response(
                message='Can\'t Sign In Now, Please Contact Administrator.',
                status_code=403).send()

    else:
        return Response(
            message='Invalid Credentials, Please Try With Another One.',
            status_code=403).send()
コード例 #11
0
 def handle_profile_picture(self, request, **kwargs):
     '''To Update/Delete Profile Picture'''
     if request.method == 'PUT':
         return Response(
             accounts_services.update_profile_picture(
                 request.user,
                 account_id=kwargs.get('pk'),
                 data=request.FILES),
             status=status.HTTP_200_OK,
             message='Profile Picture Updated Successfully.'
         )
     if request.method == 'DELETE':
         return Response(
             accounts_services.delete_profile_picture(
                 request.user,
                 account_id=kwargs.get('pk')),
             status=status.HTTP_200_OK,
             message='Profile Picture Removed Successfully.'
         )
コード例 #12
0
 def retrieve(self, request, **kwargs):
     '''
     get:
     Retrieve Single Reservation
     '''
     return Response(
         reservation_services.retrieve_reservation(
             request.user,
             reservation_pk=kwargs.get('pk'),
             query_params=request.query_params))
コード例 #13
0
 def list(self, request, **kwargs):
     '''
     get:
     List/Filter Reservations extra queries: flight_number, date
     '''
     reservations = reservation_services.filter_reservations(
         request.user, request.query_params)
     return Response(
         paginate(serializer=reservation_serializers.ReservationSerializer,
                  query_set=reservations,
                  request=request))
コード例 #14
0
 def daily_schedule(self, request, **kwargs):
     '''
     post:
     Schedule Regular daily flights for airline
     '''
     return Response(reservation_services.bulk_schedule_flight(
         request.user,
         period_type='days',
         airline_code=kwargs.get('pk'),
         data=request.data),
                     message='Flights Scheduled Successfully',
                     status=status.HTTP_201_CREATED)
コード例 #15
0
    def schedule(self, request, **kwargs):
        '''
        get:
        Retrieve Flight schedule for Airline

        post:
        Create Single airline flight schedule
        '''
        if request.method == 'GET':
            return Response(
                reservation_services.retrieve_flight_for_airline(
                    request.user,
                    airline_code=kwargs.get('pk'),
                    query_params=request.query_params),
                message='Available Flights For Airline: {} Returned'.format(
                    kwargs.get('pk')))
        if request.method == 'POST':
            return Response(reservation_services.schedule_flight(
                request.user, airline_code=kwargs.get('pk'),
                data=request.data),
                            message='Flight Scheduled Successfully',
                            status=status.HTTP_201_CREATED)
コード例 #16
0
    def reservations(self, request, **kwargs):
        '''
        get:
        View Reservations for account based on account id extra queries: flight_number, date

        post:
        Create Reservation For account based on account id
        '''
        if request.method == 'GET':
            reservations = reservation_services.filter_reservations(
                request.user,
                request.query_params,
                account_pk=kwargs.get('pk'))

            return Response(
                paginate(
                    serializer=reservation_serializers.ReservationSerializer,
                    query_set=reservations,
                    request=request))
        if request.method == 'POST':
            return Response(reservation_services.make_reservation(
                request.user, account_pk=kwargs.get('pk'), data=request.data),
                            status=status.HTTP_201_CREATED,
                            message='Reservation made Successfully.')
コード例 #17
0
    def auth_user(self, request, **kwargs):
        '''
        To authenticate a user -
        returns the users details with a token used
        Also creates a cookie with the token
        '''
        cookie_expiration = datetime.utcnow() + api_settings.JWT_EXPIRATION_DELTA

        authenticated_user, token = accounts_services.authenticate_user(
            request,
            data=request.data
        )

        response = Response(
            authenticated_user,
            message='Sign in Successful.',
        )
        response.set_cookie(
            api_settings.JWT_AUTH_COOKIE,
            token,
            expires=cookie_expiration,
            httponly=True
        )
        return response
コード例 #18
0
 def filter_reservations_by_year(self, request, **kwargs):
     '''
     get:
     Filter Reservations by year
     '''
     reservations = reservation_services.filter_reservations_by_period(
         request.user,
         month=0,
         period='year',
         year=kwargs.get('year', 0),
         query_params=request.query_params)
     return Response(
         paginate(
             serializer=reservation_serializers.ReservationSerializer,
             query_set=reservations,
             request=request,
         ))
コード例 #19
0
    def filter_reservations_by_month(self, request, **kwargs):
        '''
        get:
        Filter Reservations by year and month extra queries: flight_number, date
        '''
        reservations = reservation_services.filter_reservations_by_period(
            request.user,
            month=kwargs.get('month', 0),
            period='month',
            year=kwargs.get('year', 0),
            query_params=request.query_params)

        return Response(
            paginate(
                serializer=reservation_serializers.ReservationSerializer,
                query_set=reservations,
                request=request,
            ))
コード例 #20
0
 def wrapper(*args, **kwargs):
     """Reset Error In Every Request"""
     form_data = request.values
     errors = {}
     """Username Validation"""
     if 'username' in form_data and len(form_data.get('username')) > 0:
         if not isinstance(form_data.get('username'), str):
             errors.update({'username': '******'})
     else:
         errors.update({'username': '******'})
     """Message Validation"""
     if 'password' in form_data and len(form_data.get('password')) > 0:
         if not isinstance(form_data.get('password'), str):
             errors.update(
                 {'password': '******'})
     else:
         errors.update({'password': '******'})
     """Return error if error exists, Otherwise move forward"""
     return len(errors) > 0 and Response(errors=errors, status_code=406, message='Invalid Information Submitted.')\
         .send() or function(*args, **kwargs)
コード例 #21
0
def logout():
    session = get_current_session(formatted=False)
    if session:
        session.delete()

    return Response(message='Logged Out Successfully.').send()
コード例 #22
0
def handle_500_errors(e):
    return Response(message=f'{e}', status_code=500).send()
コード例 #23
0
def handle_404_errors(e):
    return Response(message=f'{e}', status_code=404).send()