403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/api.hellogtx.com/apihellogtx/flightinventory/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/api.hellogtx.com/apihellogtx/flightinventory/views.py
from django.shortcuts import render
import requests
import json
from datetime import date
from django.http import Http404
from rest_framework.views import APIView
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.status import (
    HTTP_400_BAD_REQUEST,
    HTTP_404_NOT_FOUND,
    HTTP_200_OK,
    HTTP_500_INTERNAL_SERVER_ERROR
)
from flightinventory.filters import AirLinePriceFilter, AirLineInventoryFilter
from django_filters.rest_framework import DjangoFilterBackend
from flightinventory.serializers import AirLinePriceHistorySerializer, FlightInventorySerializer, \
    AirLineInventorySerializer, AirLinePriceSerializer, \
    IsDeleteFlightInventorySerializer, CancellationRulesSerializer, UpdateIsRefundableAirLinePriceSerializer, \
    UpdateSeatInPriceTableSerializer, AgencyToAgencyMappingSerializer
from django.core.exceptions import ObjectDoesNotExist
from flightinventory.models import FlightInventory, AirLineInventory, AirLinePrice, \
    CancellationRules, AirLinePriceHistory, agencyToAgencyMapping


class FlightInventoryRequest(APIView):

    def get(self, request, format=None):
        try:
            data = FlightInventory.objects.all().order_by('-id')
            serializer = FlightInventorySerializer(data, many=True)
            return Response(serializer.data, status=HTTP_200_OK)
        except ObjectDoesNotExist as e:
            return Response({'error': str(e), "status": False}, status=HTTP_404_NOT_FOUND)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)

    def post(self, request):
        serializer = FlightInventorySerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=HTTP_200_OK)
        return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)


class UpdateFlightInventory(APIView):

    def get_object(self, pk):
        try:
            return FlightInventory.objects.get(pk=pk)
        except FlightInventory.DoesNotExist:
            raise Http404

    def put(self, request, pk, format=None):
        FlightInventory = self.get_object(pk)
        serializer = FlightInventorySerializer(FlightInventory, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=HTTP_200_OK)
        return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)


class GetFlightInventory(APIView):

    def get(self, request, pk, format=None):
        try:
            data = FlightInventory.objects.get(pk=pk)
            serializer = FlightInventorySerializer(data, many=False)
            return Response(serializer.data, status=HTTP_200_OK)
        except ObjectDoesNotExist as e:
            return Response({'error': str(e), "status": False}, status=HTTP_404_NOT_FOUND)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class GetCustomerFlightInventory(APIView):

    def get(self, request, **kwargs):
        try:
            fromAirportCode = kwargs['fromAirportCode']
            toAirportCode = kwargs['toAirportCode']
            travelDate = kwargs['travelDate']
            print(toAirportCode)
            print(travelDate)
            print(fromAirportCode)
            data = FlightInventory.objects.all().order_by('-id')
            serializer = FlightInventorySerializer(data, many=True)
            return Response(serializer.data, status=HTTP_200_OK)
        except ObjectDoesNotExist as e:
            return Response({'error': str(e), "status": False}, status=HTTP_404_NOT_FOUND)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


'''hjgsdhjsdgfgsdfshd'''


class FlightInventoryCheckCancelV1ApiView(APIView):
    def get(self, request, **kwargs):
        security_key = self.request.query_params.get('SecurityKey', None)
        booking_id = self.request.query_params.get('BookingId', None)
        adult = self.request.query_params.get('Adult', 0)
        child = self.request.query_params.get('Child', 0)
        infant = self.request.query_params.get('Infant', 0)
        cancellation_type = self.request.query_params.get('CancellationType', 1)
        cancellation_source = self.request.query_params.get('CancellationSource', None)
        url = "https://gtxapi.hellogtx.com/api/v2/check-cancellation-result"
        try:
            myobj = {
                        'SecurityKey': security_key,
                        'BookingId': booking_id,
                        'Adult': adult,
                        'Child': child,
                        'Infant': infant,
                        'CancellationType': cancellation_type,
                        'CancellationSource': cancellation_source
                     }

            r = requests.post(url, data=myobj)
            x = r.text
            json_data = json.loads(x)
            new_dict = {'count': 1, 'next': '', "previous": '', 'results': json_data}
            return Response(new_dict)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FlightInventoryCancelV1ApiView(APIView):
    def get(self, request, **kwargs):
        security_key = self.request.query_params.get('SecurityKey', None)
        booking_id = self.request.query_params.get('BookingId', None)
        adult = self.request.query_params.get('Adult', 0)
        child = self.request.query_params.get('Child', 0)
        infant = self.request.query_params.get('Infant', 0)
        cancellation_type = self.request.query_params.get('CancellationType', 1)
        cancellation_source = self.request.query_params.get('CancellationSource', None)
        url = "https://gtxapi.hellogtx.com/api/v2/get-cancellation-result"
        try:
            myobj = {
                        'SecurityKey': security_key,
                        'BookingId': booking_id,
                        'Adult': adult,
                        'Child': child,
                        'Infant': infant,
                        'CancellationType': cancellation_type,
                        'CancellationSource': cancellation_source
                     }
            r = requests.post(url, data=myobj)
            x = r.text
            json_data = json.loads(x)
            new_dict = {'count': 1, 'next': '', "previous": '', 'results': json_data}
            return Response(new_dict)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class CheckAutoTicketCancelApiView(APIView):
    def get(self, request, **kwargs):
        security_key = self.request.query_params.get('SecurityKey', None)
        booking_id = self.request.query_params.get('BookingId', None)
        adult = self.request.query_params.get('Adult', 0)
        child = self.request.query_params.get('Child', 0)
        infant = self.request.query_params.get('Infant', 0)
        cancellation_type = self.request.query_params.get('CancellationType', 1)
        url = "https://gtxapi.hellogtx.com/api/v2/check-cancellation-result-auto-ticket"
        try:
            myobj = {
                        'SecurityKey': security_key,
                        'BookingId': booking_id,
                        'Adult': adult,
                        'Child': child,
                        'Infant': infant,
                        'CancellationType': cancellation_type
                     }

            r = requests.post(url, data=myobj)
            x = r.text
            json_data = json.loads(x)
            new_dict = {'count': 1, 'next': '', "previous": '', 'results': json_data}
            return Response(new_dict)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class UpdateAutoTicketCancelApiView(APIView):
    def get(self, request, **kwargs):
        security_key = self.request.query_params.get('SecurityKey', None)
        booking_id = self.request.query_params.get('BookingId', None)
        adult = self.request.query_params.get('Adult', 0)
        child = self.request.query_params.get('Child', 0)
        infant = self.request.query_params.get('Infant', 0)
        cancellation_type = self.request.query_params.get('CancellationType', 1)
        url = "https://gtxapi.hellogtx.com/api/v2/update-cancellation-result-auto-ticket"
        try:
            myobj = {
                        'SecurityKey': security_key,
                        'BookingId': booking_id,
                        'Adult': adult,
                        'Child': child,
                        'Infant': infant,
                        'CancellationType': cancellation_type
                     }
            r = requests.post(url, data=myobj)
            x = r.text
            json_data = json.loads(x)
            new_dict = {'count': 1, 'next': '', "previous": '', 'results': json_data}
            return Response(new_dict)
        except Exception as e:
            return Response({'error': str(e), "status": False}, status=HTTP_500_INTERNAL_SERVER_ERROR)


class FlightInventoryCancelApiView(generics.ListCreateAPIView):
    queryset = AirLinePriceHistory.objects.all()
    serializer_class = AirLinePriceHistorySerializer

    def get_queryset(self):
        security_key = self.request.query_params.get('SecurityKey', None)
        booking_id = self.request.query_params.get('BookingId', None)
        adult = self.request.query_params.get('Adult', 0)
        child = self.request.query_params.get('Child', 0)
        infant = self.request.query_params.get('Infant', 0)
        if security_key is not None and booking_id is not None:
            if int(adult) > 0 or int(child) > 0 or int(infant) > 0:
                return self.queryset.filter(HistoryId=booking_id,
                                            InventoryStatus=1,
                                            Adult__gte=adult,
                                            Child__gte=child,
                                            Infant__gte=infant)
            else:
                return []
        else:
            return []


class FlightInventoriesApiView(generics.ListCreateAPIView):
    queryset = FlightInventory.objects.all()
    serializer_class = FlightInventorySerializer

    def get_queryset(self):
        security_key = self.request.query_params.get('SecurityKey', None)
        flight_type = self.request.query_params.get('FlightType', None)
        if security_key is not None:
            if flight_type is not None:
                oneway_from_airport_code = self.request.query_params.get('OFAC', None)
                oneway_to_airport_code = self.request.query_params.get('OTAC', None)
                round_from_airport_code = self.request.query_params.get('RFAC', None)
                round_to_airport_code = self.request.query_params.get('RTAC', None)
                today = date.today()
                if flight_type == '1':
                    if oneway_from_airport_code is not None and oneway_to_airport_code is not None:
                        filter_qs = FlightInventory.objects.raw(" SELECT * FROM flightinventory_flightinventory as T1"
                                                                " LEFT JOIN flightinventory_airlineinventory as T2 ON"
                                                                " T1.id = T2.FlightInventory_id"
                                                                " LEFT JOIN flightinventory_airlineprice as T3 ON"
                                                                " T1.id = T3.FlightInventory_id"
                                                                " WHERE T3.FromDate >= '" + str(
                            today) + "' AND T1.FlightType='" + flight_type + "'"
                                                                             " AND OnwardFromAirportCode='" + oneway_from_airport_code + "' AND OnwardToAirportCode='" + oneway_to_airport_code + "'"
                                                                                                                                                                                                  " GROUP BY T1.id ")
                        return filter_qs
                    else:
                        return self.queryset.filter(airlineprices__FromDate__gte=today, SecurityKey=security_key,
                                                    FlightType=flight_type)
                elif flight_type == '2':
                    if oneway_from_airport_code is not None and oneway_to_airport_code is not None \
                            and round_from_airport_code is not None and round_to_airport_code is not None:
                        query_result = self.queryset.filter(airlineprices__FromDate__gte=today,
                                                            # airlineprices__FromDate=today,
                                                            SecurityKey=security_key,
                                                            FlightType=flight_type,
                                                            OnwardFromAirportCode=oneway_from_airport_code,
                                                            OnwardToAirportCode=oneway_to_airport_code,
                                                            InwardFromAirportCode=round_from_airport_code,
                                                            InwardToAirportCode=round_to_airport_code)
                        return query_result
                    else:
                        return self.queryset.filter(airlineprices__FromDate__gte=today, SecurityKey=security_key,
                                                    FlightType=flight_type).order_by('-id')
            else:
                filter_qs = FlightInventory.objects.raw(" SELECT T2.*,T3.*,T4.* FROM flightinventory_agencytoagencymapping AS T1 Left JOIN flightinventory_flightinventory AS T2 ON T2.SecurityKey = T1.SecurityKey LEFT JOIN flightinventory_airlineinventory AS T3 ON T2.id = T3.FlightInventory_id LEFT JOIN flightinventory_airlineprice AS T4 ON T2.id = T4.FlightInventory_id WHERE ( T1.MasterSecurityKey = '"+security_key+"' ) AND T2.IsActive = '1' AND T2.IsMarkForDelete = '0' GROUP BY T2.id ORDER BY T2.id DESC ")
                return filter_qs
        return []


class CancellationRulesListApiView(generics.ListCreateAPIView):
    queryset = CancellationRules.objects.all()
    serializer_class = CancellationRulesSerializer

    def get_queryset(self):
        security_key = self.request.query_params.get('SecurityKey', None)
        days = self.request.query_params.get('Days', None)
        is_master = self.request.query_params.get('IsMaster', False)
        airline_price_id = self.request.query_params.get('AirLinePrice', None)
        if security_key is not None:
            if airline_price_id is not None:
                if days is not None:
                    return self.queryset.filter(AirLinePrice=airline_price_id, Days=days, SecurityKey=security_key,
                                                IsMaster=is_master, IsMarkForDelete=False).order_by('Days')
                else:
                    return self.queryset.filter(AirLinePrice=airline_price_id, SecurityKey=security_key,
                                                IsMaster=is_master, IsMarkForDelete=False).order_by('Days')

            elif days is not None:
                return self.queryset.filter(SecurityKey=security_key, Days=days, IsMaster=is_master,
                                            IsMarkForDelete=False) \
                    .order_by('Days')
            else:
                return self.queryset.filter(SecurityKey=security_key, IsMaster=True, IsMarkForDelete=False) \
                    .order_by('Days')
        return []


class CancellationRulesApiView(generics.RetrieveUpdateDestroyAPIView):
    queryset = CancellationRules.objects.all()
    serializer_class = CancellationRulesSerializer


class FlightInventoryApiView(generics.RetrieveUpdateDestroyAPIView):
    queryset = FlightInventory.objects.all()
    serializer_class = FlightInventorySerializer


class CheckFlightInventoryApiView(generics.RetrieveUpdateAPIView):
    queryset = AirLinePrice.objects.all()
    serializer_class = AirLinePriceSerializer


class DeleteFlightInventoryApiView(generics.UpdateAPIView):
    queryset = FlightInventory.objects.all()
    serializer_class = IsDeleteFlightInventorySerializer


class UpdateIsRefundableInPrice(generics.UpdateAPIView):
    queryset = AirLinePrice.objects.all()
    serializer_class = UpdateIsRefundableAirLinePriceSerializer


class UpdateSeatInPriceTable(generics.RetrieveUpdateAPIView):
    queryset = AirLinePrice.objects.all()
    serializer_class = UpdateSeatInPriceTableSerializer


class CreateSecurityCodeMapping(generics.CreateAPIView):
    queryset = agencyToAgencyMapping.objects.all()
    serializer_class = AgencyToAgencyMappingSerializer




Youez - 2016 - github.com/yon3zu
LinuXploit