Example #1
0
def ListProductsHistory(request, pk):

    context = {}

    prod_obj = get_object_or_404(Product, pk=pk)

    api = ApiDomains()
    url = api.product + "/" + "history"
    #url = 'https://94q78vev60.execute-api.us-east-1.amazonaws.com/Prod/intellidataProductAPI/history'
    payload = {'ident': prod_obj.productid}

    resp = requests.get(url, params=payload)
    print(resp.status_code)
    obj = get_object_or_404(APICodes, http_response_code=resp.status_code)
    status_message = obj.http_response_message
    mesg = str(resp.status_code) + " - " + status_message

    if resp.status_code != 200:
        # This means something went wrong.
        #raise ApiError('GET /tasks/ {}'.format(resp.status_code))
        #raise APIError(resp.status_code)
        message = {'messages': mesg}
        return render(request, "messages.html", context=message)
    else:
        json_data = []
        dict_data = []
        obj_data = []
        json_data = resp.json()

        #print(json_data[0])
        #print(json_data[1])
        for ix in range(len(json_data)):
            obj = Product()
            #dict_data.append(json.loads(json_data[ix]))
            obj.pk = int(json_data[ix]["LOCAL_ID"])
            obj.productid = json_data[ix]["PRODUCT_ID"]
            obj.name = json_data[ix]["NAME"]
            obj.type = json_data[ix]["TYPE"]
            obj.coverage_limit = json_data[ix]["COVERAGE_LIMIT"]
            obj.price_per_1000_units = json_data[ix]["RATE"]
            obj.product_date = json_data[ix]["CREATE_DATE"]
            obj.description = json_data[ix]["DESCRIPTION"]
            obj.description_html = misaka.html(obj.description)
            #obj.photo = json_data[ix]["PHOTO"]
            obj.creator = User.objects.get(pk=int(json_data[ix]["CREATOR"]))
            obj.create_date = json_data[ix]["CREATE_DATE"]
            obj.backend_SOR_connection = json_data[ix]["CONNECTION"]
            obj.response = json_data[ix]["RESPONSE"]
            obj.record_status = json_data[ix]["RECORD_STATUS"]
            obj.commit_indicator = json_data[ix]["COMMIT_INDICATOR"]

            obj_data.append(obj)

        context = {'object_list': obj_data}

        return render(request, "products/product_list.html", context=context)
Example #2
0
def ProductList(request):

    if request.method == 'GET':
        contacts = Product.objects.all()
        serializer = ProductSerializer(contacts, many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = ProductSerializer(data=request.data)

        serializer.is_valid(raise_exception=True)
        product = Product()
        event = Event()

        if serializer.data["productid"] == '':
            product.productid = str(uuid.uuid4())[26:36]
            event.EventTypeReason = "New product received via API"
        else:
            product.productid = serializer.data["productid"]
            event.EventTypeReason = "Product added via API"

        product.name = serializer.data["name"]
        product.slug = slugify(product.name),

        product.description = serializer.data["description"]
        product.description_html = misaka.html(product.description),
        product.coverage_limit = serializer.data["coverage_limit"]
        product.price_per_1000_units = serializer.data["price_per_1000_units"]

        product.source = "Post API"

        product.creator = get_object_or_404(User,
                                            pk=serializer.data["creator"])

        product.backend_SOR_connection = "Disconnected"
        product.response = ""
        product.commit_indicator = "Not Committed"
        product.record_status = ""
        product.bulk_upload_indicator = "Y"

        #Log events
        event.EventTypeCode = "PRW"
        event.EventSubjectId = product.productid
        event.EventSubjectName = product.name
        event.source = "Post API"
        event.creator = product.creator
        event.save()

        product.save()
        return Response(serializer.data)
Example #3
0
    def get_queryset(self, **kwargs):  # new
        query = self.request.GET.get('q', None)
        object_list = Product.objects.filter(
            Q(productid__icontains=query) | Q(name__icontains=query)
            | Q(type__icontains=query) | Q(description__icontains=query))

        #change start for remote SearchProductsForm
        if not object_list:
            api = ApiDomains()
            url = api.product + "/" + "refresh"
            #url = 'https://94q78vev60.execute-api.us-east-1.amazonaws.com/Prod/intellidataProductAPI/history'
            payload = {'ident': query}

            resp = requests.get(url, params=payload)
            print(resp.status_code)

            obj = get_object_or_404(APICodes,
                                    http_response_code=resp.status_code)
            status_message = obj.http_response_message
            mesg = str(resp.status_code) + " - " + status_message

            if resp.status_code != 200:
                # This means something went wrong.
                #raise ApiError('GET /tasks/ {}'.format(resp.status_code))
                #raise APIError(resp.status_code)
                #message={'messages':mesg}
                #return render(self.request, "messages.html", context=message)
                print("Status Code: " + str(resp.status_code))
            else:
                json_data = []

                json_data = resp.json()
                obj_data = []
                obj1 = Product()

                #OVERRIDE THE OBJECT WITH API data
                obj1.pk = int(json_data["LOCAL_ID"])
                obj1.productid = json_data["PRODUCT_ID"]
                obj1.name = json_data["NAME"]
                obj1.type = json_data["TYPE"]
                obj1.coverage_limit = json_data["COVERAGE_LIMIT"]
                obj1.price_per_1000_units = json_data["RATE"]
                obj1.product_date = json_data["CREATE_DATE"]
                obj1.description = json_data["DESCRIPTION"]
                obj1.description_html = misaka.html(obj1.description)
                #obj1.photo = json_data["PHOTO"]
                obj1.creator = User.objects.get(pk=int(json_data["CREATOR"]))
                #obj.crerator = get_object_or_404(User, pk=obj.creatorid)
                obj1.create_date = json_data["CREATE_DATE"]
                obj1.backend_SOR_connection = "Disconnected"
                obj1.response = "Pulled From Backend"
                obj1.commit_indicator = json_data["COMMIT_INDICATOR"]
                obj1.record_status = json_data["RECORD_STATUS"]

                obj1.save()

                #obj_data.append(obj1)
                #print(obj_data)

                #context = {'object_list':obj_data}

                #return render(self.request, "products/product_search_list.html", context=context)
                object_remote_list = Product.objects.filter(productid=query)
                print(object_remote_list)
                return object_remote_list

        else:
            #change end for remote SearchProductsForm

            return object_list
Example #4
0
def RefreshProduct(request, pk):
    # fetch the object related to passed id
    context = {}
    prod_obj = get_object_or_404(Product, pk=pk)

    api = ApiDomains()
    url = api.product + "/" + "refresh"
    #url = 'https://94q78vev60.execute-api.us-east-1.amazonaws.com/Prod/intellidataProductAPI/history'
    payload = {'ident': prod_obj.productid}

    resp = requests.get(url, params=payload)
    print(resp.status_code)

    obj = get_object_or_404(APICodes, http_response_code=resp.status_code)
    status_message = obj.http_response_message
    mesg = str(resp.status_code) + " - " + status_message

    if resp.status_code != 200:
        # This means something went wrong.
        #raise ApiError('GET /tasks/ {}'.format(resp.status_code))
        #raise APIError(resp.status_code)
        message = {'messages': mesg}
        return render(request, "messages.html", context=message)
    else:
        json_data = []

        json_data = resp.json()
        obj1 = Product()

        #OVERRIDE THE OBJECT WITH API data
        obj1.pk = int(json_data["LOCAL_ID"])
        obj1.productid = json_data["PRODUCT_ID"]
        obj1.name = json_data["NAME"]
        obj1.type = json_data["TYPE"]
        obj1.coverage_limit = json_data["COVERAGE_LIMIT"]
        obj1.price_per_1000_units = json_data["RATE"]
        obj1.product_date = json_data["CREATE_DATE"]
        obj1.description = json_data["DESCRIPTION"]
        obj1.description_html = misaka.html(obj1.description)
        #obj1.photo = json_data["PHOTO"]
        obj1.creator = User.objects.get(pk=int(json_data["CREATOR"]))
        #obj.crerator = get_object_or_404(User, pk=obj.creatorid)
        obj1.create_date = json_data["CREATE_DATE"]
        obj1.backend_SOR_connection = "Disconnected"
        obj1.response = json_data["RESPONSE"]
        obj1.commit_indicator = json_data["COMMIT_INDICATOR"]
        obj1.record_status = json_data["RECORD_STATUS"]

        #Log events
        event = Event()
        event.EventTypeCode = "PRR"
        event.EventSubjectId = obj1.productid
        event.EventSubjectName = obj1.name
        event.EventTypeReason = "Product refreshed from ODS"
        event.source = "Online Transaction"
        event.creator = obj1.creator
        event.save()

        obj1.save()

        context = {'product_details': obj1}

        return render(request, "products/product_detail.html", context=context)