def delete_product(request): try: requestbody = request.body.decode("utf-8") product = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(product) or not "productID" in product or not validate_integer( product["productID"]): return customResponse(400, error_code=5, error_details="Id for product not sent") productPtr = Product.objects.filter(id=int(product["productID"]), delete_status=False) if len(productPtr) == 0: return customResponse(400, error_code=6, error_details="Invalid id for product sent") productPtr = productPtr[0] try: productPtr.delete_status = True productPtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=3) else: closeDBConnection() return customResponse(200, {"product": "product deleted"})
def post_new_buyer_contacts(request, parameters): try: requestbody = request.body.decode("utf-8") buyer_contacts = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer_contacts) or not "contacts" in buyer_contacts or not isinstance(buyer_contacts["contacts"], list) or not len(buyer_contacts["contacts"]) > 0: return customResponse(400, error_code=5, error_details= "Invalid data sent in request") buyerPtr = Buyer.objects.filter(id=parameters["buyersArr"][0], delete_status=False) if not buyerPtr.exists(): return customResponse(400, error_code=6, error_details= "Invalid id for buyer sent") if not validateBuyerContactsData(buyer_contacts["contacts"]): return customResponse(400, error_code=5, error_details= "Contact Id not sent") if not "firebase_token" in buyer_contacts or buyer_contacts["firebase_token"] == None: buyer_contacts["firebase_token"] = str(uuid.uuid1()) try: for buyer_contact in buyer_contacts["contacts"]: buyerContactsPtr, created = BuyerContacts.objects.get_or_create(buyer_id = parameters["buyersArr"][0], client_contact_id = buyer_contact["contactID"], firebase_token = buyer_contacts["firebase_token"]) buyerContactsPtr.emails = ','.join([x.encode('utf-8') for x in buyer_contact["mailArr"]]) buyerContactsPtr.numbers = ','.join([x.encode('utf-8') for x in buyer_contact["numbersArr"]]) buyerContactsPtr.contact_name = buyer_contact["name"] buyerContactsPtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code = 1) else: closeDBConnection() return customResponse(200, {"success" : "contacts saved"})
def get_pincode_serviceability_details(request, parameters={}): try: serviceable_pincodes = filterServiceablePincodes(parameters) paginator = Paginator(serviceable_pincodes, parameters["itemsPerPage"]) try: pageItems = paginator.page(parameters["pageNumber"]) except Exception as e: pageItems = [] body = parseServiceablePincodes(pageItems, parameters) response = {"serviceable_pincodes": body} responsePaginationParameters(response, paginator, parameters) closeDBConnection() statusCode = 200 except Exception as e: log.critical(e) statusCode = 500 body = {} return customResponse(statusCode, response, error_code=0)
def get_buyer_renew_access_token(request, parameters): refresh_token = getAccessToken(request, "refresh_token") if refresh_token == "": return customResponse(400, error_code=5, error_details="Refresh token not sent") tokenPayload = validateBuyerRefreshToken(refresh_token) if tokenPayload == {}: return customResponse(403, error_code=7, error_details="Token invalid") buyerRefreshTokenPtr = BuyerRefreshToken.objects.filter( id=int(tokenPayload["jti"])) buyerRefreshTokenPtr = buyerRefreshTokenPtr[0] try: newBuyerAccessToken = BuyerAccessToken() newBuyerAccessToken.populateFromRefreshToken(buyerRefreshTokenPtr) newBuyerAccessToken.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: response_body = {} response_body["access_token"] = serialize_buyer_access_token( newBuyerAccessToken, parameters) closeDBConnection() return customResponse(200, {"buyer_login": response_body})
def put_buyer_firebase_token_details(request, parameters): try: requestbody = request.body.decode("utf-8") buyer = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer) or not BuyerFireBaseToken.validateBuyerFireBaseTokenData( buyer): return customResponse(400, error_code=5, error_details="Invalid data sent in request") try: buyerID = parameters["buyersArr"][0] except Exception as e: buyerID = None try: buyerFireBaseTokenPtr, created = BuyerFireBaseToken.objects.get_or_create( instance_id=buyer["instance_id"]) buyerFireBaseTokenPtr.buyer_id = buyerID buyerFireBaseTokenPtr.token = buyer["token"] buyerFireBaseTokenPtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: return customResponse(200, {"token": "token successfully created"})
def delete_article(request): try: requestbody = request.body.decode("utf-8") article = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(article) or not "articleID" in article or not validate_integer( article["articleID"]): return customResponse(400, error_code=5, error_details="Id for article not sent") articlePtr = Article.objects.filter(id=int(article["articleID"])) if len(articlePtr) == 0: return customResponse(400, error_code=6, error_details="Invalid ID for article sent") articlePtr = articlePtr[0] try: articlePtr.delete_status = True articlePtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=3) else: closeDBConnection() return customResponse(200, {"body": "article deleted"})
def delete_buyer_buys_from(request, parameters): try: requestbody = request.body.decode("utf-8") buyer_buys_from = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len( buyer_buys_from ) or not "buyerbuysfromID" in buyer_buys_from or not validate_integer( buyer_buys_from["buyerbuysfromID"]): return customResponse(400, error_code=5, error_details="Id for buyer buys_from not sent") buyerBuysFromPtr = BuyerBuysFrom.objects.filter( id=int(buyer_buys_from["buyerbuysfromID"])) if len(buyerBuysFromPtr) == 0: return customResponse( 400, error_code=6, error_details="Invalid id for buyer buys_from sent") try: buyerBuysFromPtr.update(delete_status=True, updated_at=timezone.now()) except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=3) else: closeDBConnection() return customResponse(200, {"buyer": "buyer buys_from deleted"})
def post_new_category(request): try: requestbody = request.body.decode("utf-8") category = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(category) or not validateCategoryData(category, Category(), 1): return customResponse(400, error_code=5, error_details="Invalid data for category sent") category["slug"] = slugify(category["name"]) try: newCategory = Category() populateCategoryData(newCategory, category) newCategory.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: closeDBConnection() return customResponse( 200, {"categories": serialize_categories(newCategory)})
def delete_buyer(request, parameters): try: requestbody = request.body.decode("utf-8") buyer = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer) or not "buyerID" in buyer or not buyer[ "buyerID"] or not validate_integer(buyer["buyerID"]): return customResponse(400, error_code=5, error_details="Id for buyer not sent") buyerPtr = Buyer.objects.filter(id=int(buyer["buyerID"]), delete_status=False) if len(buyerPtr) == 0: return customResponse(400, error_code=6, error_details="Invalid id for buyer sent") buyerPtr = buyerPtr[0] try: buyerPtr.delete_status = True buyerPtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=3) else: closeDBConnection() return customResponse(200, {"buyer": "buyer deleted"})
def get_categories_details(request, parameters): try: if "isBuyer" in parameters and parameters["isBuyer"] == 1: parameters["category_show_online"] = 1 elif "isBuyerStore" in parameters and parameters["isBuyerStore"] == 1: parameters["category_show_online"] = 1 elif "isSeller" in parameters and parameters["isSeller"] == 1: pass elif "isInternalUser" in parameters and parameters[ "isInternalUser"] == 1: pass else: parameters["category_show_online"] = 1 categories = filterCategories(parameters) statusCode = 200 body = {"categories": categories_parser(categories, parameters)} except Exception as e: log.critical(e) statusCode = 500 body = {} closeDBConnection() return customResponse(statusCode, body, error_code=0)
def get_buyer_product_response_count_details(request, parameters={}): try: if not "buyersArr" in parameters: return customResponse(400, error_code=5, error_details="Id for buyer not sent") buyerID = parameters["buyersArr"][0] buyerProductResponseCount = BuyerProductResponse.objects.filter( product__delete_status=False, product__seller__delete_status=False, product__seller__show_online=True, product__category__delete_status=False, buyer_id=buyerID, response_code=1).count() response = {"like_count": buyerProductResponseCount} statusCode = 200 except Exception as e: log.critical(e) statusCode = 500 response = {} closeDBConnection() return customResponse(statusCode, response)
def post_new_buyer_panel_tracking(request, parameters): try: requestbody = request.body.decode("utf-8") buyer = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) #if not len(buyer) or not "buyerID" in buyer or not validate_integer(buyer["buyerID"]): # return customResponse("4XX", {"error": "Id for buyer not sent"}) buyer["buyerID"] = parameters["buyersArr"][0] buyerPtr = Buyer.objects.filter(id=int(buyer["buyerID"]), delete_status=False) if not buyerPtr.exists(): return customResponse(400, error_code=6, error_details= "Invalid id for buyer sent") if not "page_closed" in buyer or buyer["page_closed"] ==None: return customResponse(400, error_code=6, error_details= "Page number not sent") try: newBuyerPanelInstructionsTracking = BuyerPanelInstructionsTracking(buyer_id=int(buyer["buyerID"]), page_closed=buyer["page_closed"]) newBuyerPanelInstructionsTracking.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code = 1) else: closeDBConnection() return customResponse(200, {"buyer_product_tracking":"successfully added"})
def get_buyer_product_details(request, parameters={}): try: parameters["buyer_product_delete_status"] = False parameters["buyer_interest_active"] = True parameters["responded"] = 0 buyerProducts = filterBuyerProducts(parameters) paginator = Paginator(buyerProducts, parameters["itemsPerPage"]) try: pageItems = paginator.page(parameters["pageNumber"]) except Exception as e: pageItems = [] body = parse_buyer_product(pageItems, parameters) statusCode = 200 response = {"buyer_products": body} responsePaginationParameters(response, paginator, parameters) except Exception as e: log.critical(e) statusCode = 500 response = {} closeDBConnection() return customResponse(statusCode, response)
def update_buyer_store_url(request, parameters): try: requestbody = request.body.decode("utf-8") buyer = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) buyer["buyerID"] = parameters["buyersArr"][0] buyerPtr = Buyer.objects.filter(id=int(buyer["buyerID"]), delete_status=False) if not buyerPtr.exists(): return customResponse(400, error_code=6, error_details= "Invalid id for buyer sent") buyerPtr = buyerPtr[0] if not buyerPtr.validateBuyerStoreUrlData(buyer): return customResponse(400, error_code=5, error_details= "Invalid data sent") if Buyer.objects.exclude(id=int(buyer["buyerID"])).filter(store_url = buyer["store_url"]).exists(): return customResponse(400, error_code=6, error_details= "Store url already exists") try: buyerPtr.store_url = buyer["store_url"] buyerPtr.store_active = int(buyer["store_active"]) buyerPtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code = 1) else: closeDBConnection() return customResponse(200, {"buyer_store_url":"successfully updated"})
def get_deleted_offline_products(request, parameters={}): try: response = {} if not "product_updated_at" in parameters: parameters["product_updated_at"] = "2016-01-01T00:00:00.000Z" response["offline_products"] = ",".join( map( str, Product.objects.filter( updated_at__gte=parameters["product_updated_at"], show_online=0).values_list('id', flat=True))) response["deleted_products"] = ",".join( map( str, Product.objects.filter( updated_at__gte=parameters["product_updated_at"], delete_status=1).values_list('id', flat=True))) statusCode = 200 except Exception as e: log.critical(e) statusCode = 500 response = {} closeDBConnection() return customResponse(statusCode, response, error_code=0)
def update_buyer_address(request, parameters): try: requestbody = request.body.decode("utf-8") buyer_address = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if parameters["isBuyer"] == 1: buyer_address["buyerID"] = parameters["buyersArr"][0] elif not "buyerID" in buyer_address or not validate_integer( buyer_address["buyerID"]): return customResponse(400, error_code=5, error_details="Id for buyer not sent") if not len(buyer_address): return customResponse( 400, error_code=5, error_details="Invalid data for buyer address sent") if not "addressID" in buyer_address or not validate_integer( buyer_address["addressID"]): return customResponse(400, error_code=5, error_details="Address Id for buyer not sent") buyerAddressPtr = BuyerAddress.objects.filter( buyer_id=int(buyer_address["buyerID"]), id=int(buyer_address["addressID"])) if len(buyerAddressPtr) == 0: return customResponse( 400, error_code=6, error_details="Invalid Address Id for buyer sent") buyerAddressPtr = buyerAddressPtr[0] validateBuyerAddressData(buyer_address, BuyerAddress(), 0) try: populateBuyerAddress(buyerAddressPtr, buyer_address) buyerAddressPtr.save() newBuyerAddressHistory = BuyerAddressHistory() newBuyerAddressHistory.populateFromBuyerAddress(buyerAddressPtr) newBuyerAddressHistory.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: closeDBConnection() return customResponse( 200, {"address": serialize_buyer_address(buyerAddressPtr)})
def post_new_buyer_registration(request, parameters): try: requestbody = request.body.decode("utf-8") buyer_registration = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer_registration) or not validateBuyerRegistrationData( buyer_registration): return customResponse( 400, error_code=5, error_details="Invalid data for buyer registration sent") if buyer_registration["email"] != "" and buyerEmailExists( buyer_registration["email"]): return customResponse(400, error_code=6, error_details="buyer email already exists") if buyerMobileNumberExists(buyer_registration["mobile_number"]): return customResponse( 400, error_code=6, error_details="buyer phone number already exists") ## Invalidate all registrations with same email or mobile number if buyer_registration["email"] != "": BuyerRegistration.objects.filter( email=buyer_registration["email"]).update( is_active=False, updated_at=timezone.now()) BuyerRegistration.objects.filter( mobile_number=buyer_registration["mobile_number"]).update( is_active=False, updated_at=timezone.now()) try: newBuyerRegistration = BuyerRegistration() newBuyerRegistration.populateBuyerRegistration(buyer_registration) newBuyerRegistration.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: ## Send mobile number verification SMS newBuyerRegistration.sendVerificationSMS() closeDBConnection() return customResponse( 200, { "buyer_registration": serialize_buyer_registration(newBuyerRegistration, parameters) })
def post_buyer_change_password(request, parameters): try: requestbody = request.body.decode("utf-8") buyer = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer) or not validateBuyerPasswordChangeData(buyer): return customResponse(400, error_code=5, error_details="Invalid data sent in request") refresh_token = getAccessToken(request, "refresh_token") if refresh_token == "": return customResponse(400, error_code=5, error_details="Refresh token not sent") tokenPayload = validateBuyerRefreshToken(refresh_token) if tokenPayload == {}: return customResponse(403, error_code=7, error_details="Token invalid") buyerPtr = Buyer.objects.filter(id=parameters["buyersArr"][0], delete_status=False, blocked=False) if len(buyerPtr) == 0: return customResponse(400, error_code=6, error_details="Invalid buyer id sent") buyerPtr = buyerPtr[0] if not buyerPtr.password == buyer["password"]: return customResponse(400, error_code=9, error_details="Incorrect password sent") try: buyerPtr.password = buyer["new_password"] buyerPtr.save() BuyerRefreshToken.objects.filter(buyer_id=buyerPtr.id).update( is_active=False, updated_at=timezone.now()) except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: closeDBConnection() return customResponse(200, {"success": "successfully changed password"})
def get_state_details(request, stateParameters): try: states = filterState(stateParameters) response = {"states": parse_state(states)} closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500, error_code=0)
def get_buyer_details(request, parameters={}): try: buyers = filterBuyer(parameters) response = {"buyers": parse_buyer(buyers, parameters)} closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500)
def post_new_buyer_address(request, parameters): try: requestbody = request.body.decode("utf-8") buyer_address = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if parameters["isBuyer"] == 1: buyer_address["buyerID"] = parameters["buyersArr"][0] elif not "buyerID" in buyer_address or not validate_integer( buyer_address["buyerID"]): return customResponse(400, error_code=5, error_details="Id for buyer not sent") if not len(buyer_address) or not validateBuyerAddressData( buyer_address, BuyerAddress(), 1): return customResponse( 400, error_code=5, error_details="Invalid data for buyer address sent") try: addressPresent = False if "client_id" in buyer_address and str( buyer_address["client_id"]) != "" and len( str(buyer_address["client_id"])) > 6: newAddress = BuyerAddress.objects.filter( buyer_id=int(buyer_address["buyerID"]), client_id=str(buyer_address["client_id"])) if len(newAddress) != 0: addressPresent = True newAddress = newAddress[0] if not addressPresent: newAddress = BuyerAddress(buyer_id=int(buyer_address["buyerID"])) if not BuyerAddress.objects.filter( buyer_id=int(buyer_address["buyerID"])).exists(): newAddress.priority = 0 populateBuyerAddress(newAddress, buyer_address) newAddress.save() newBuyerAddressHistory = BuyerAddressHistory() newBuyerAddressHistory.populateFromBuyerAddress(newAddress) newBuyerAddressHistory.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: closeDBConnection() return customResponse(200, {"address": serialize_buyer_address(newAddress)})
def post_new_buyer_store_lead(request, parameters): try: requestbody = request.body.decode("utf-8") buyer_store_lead = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer_store_lead): return customResponse(400, error_code=5, error_details= "Id for buyer not sent") if parameters["isBuyer"] == 1 or parameters["isBuyerStore"] == 1: buyer_store_lead["buyerID"] = parameters["buyersArr"][0] elif not "buyerID" in buyer_store_lead or not validate_integer(buyer_store_lead["buyerID"]): return customResponse(400, error_code=5, error_details= "Id for buyer not sent") buyerPtr = Buyer.objects.filter(id=int(buyer_store_lead["buyerID"]), delete_status=False) if not buyerPtr.exists(): return customResponse(400, error_code=6, error_details= "Invalid id for buyer sent") if not "productID" in buyer_store_lead or not validate_integer(buyer_store_lead["productID"]): return customResponse(400, error_code=5, error_details= "Id for product not sent") productParameters = {} productParameters["productsArr"] = [int(buyer_store_lead["productID"])] productParameters["product_verification"] = True productParameters["product_show_online"] = True productPtr = filterProducts(productParameters) if not productPtr.exists(): return customResponse(400, error_code=6, error_details= "Invalid id for product sent") newBuyerStoreLead = BuyerStoreLead(buyer_id=int(buyer_store_lead["buyerID"]), product_id = int(buyer_store_lead["productID"])) if not newBuyerStoreLead.validateBuyerStoreLeadData(buyer_store_lead, 1): return customResponse(400, error_code=5, error_details= "Invalid data for buyer store lead sent") try: newBuyerStoreLead.populateBuyerStoreLead(buyer_store_lead) newBuyerStoreLead.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code = 1) else: newBuyerStoreLead.sendRetailerMail(parameters) newBuyerStoreLead.sendCustomerMail(parameters) closeDBConnection() return customResponse(200, {"buyer_store_lead":serialize_buyer_store_lead(newBuyerStoreLead)})
def get_business_type_details(request, parameters={}): try: businessTypes = filterBusinessType(parameters) response = { "business_types": parse_business_type(businessTypes, parameters) } closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500, error_code=0)
def get_buyer_purchasing_state_details(request,parameters = {}): try: buyersPurchasingState = filterBuyerPurchasingState(parameters) response = { "buyer_purchasing_states" : parse_buyer_purchasing_state(buyersPurchasingState, parameters) } closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500)
def get_internal_user_details(request,parameters = {}): try: internalUsers = filterInternalUser(parameters) response = { "internal_users" : parseInternalUser(internalUsers, parameters) } closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500)
def get_product_fabric_details(request, parameters={}): try: productFabrics = filterProductFabricType(parameters) statusCode = 200 body = {"product_fabric_types": parseProductFabricType(productFabrics)} except Exception as e: log.critical(e) statusCode = 500 body = {} closeDBConnection() return customResponse(statusCode, body, error_code=0)
def get_buyer_store_url_exists_details(request, parameters): try: store_url = request.GET.get("store_url_exists", "") if store_url == None or len(store_url) < 6: return customResponse(400, error_code=6, error_details= "Invalid url sent") store_url_exists = Buyer.objects.filter(store_url = store_url).exists() response = { "store_url_exists" : store_url_exists } closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500)
def get_buyer_shared_product_id_details(request, parameters={}): try: buyerSharedProductID = filterBuyerSharedProductID(parameters) response = { "buyer_shared_product_id": parse_buyer_shared_product_id(buyerSharedProductID, parameters) } closeDBConnection() return customResponse(200, response) except Exception as e: log.critical(e) return customResponse(500)
def post_buyer_forgot_password(request, parameters): try: requestbody = request.body.decode("utf-8") buyer = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len(buyer) or not validateBuyerForgotPasswordData(buyer): return customResponse(400, error_code=5, error_details="Invalid data sent in request") buyerPtr = Buyer.objects.filter(mobile_number=buyer["mobile_number"], blocked=False, delete_status=False) if len(buyerPtr) == 0: return customResponse(400, error_code=6, error_details="Invalid mobile number sent") buyerPtr = buyerPtr[0] ## Invalidate all registrations with same email or mobile number BuyerForgotPasswordToken.objects.filter( mobile_number=buyer["mobile_number"]).update(is_active=False, updated_at=timezone.now()) try: newBuyerForgotPasswordToken = BuyerForgotPasswordToken() newBuyerForgotPasswordToken.populateBuyerBuyerForgotPasswordToken( buyer) newBuyerForgotPasswordToken.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=1) else: ## Send mobile number verification SMS newBuyerForgotPasswordToken.sendVerificationSMS() closeDBConnection() return customResponse( 200, { "buyer_registration": serialize_buyer_forgot_password_token( newBuyerForgotPasswordToken, parameters) })
def update_category(request): try: requestbody = request.body.decode("utf-8") category = convert_keys_to_string(json.loads(requestbody)) except Exception as e: return customResponse(400, error_code=4) if not len( category) or not "categoryID" in category or not validate_integer( category["categoryID"]): return customResponse(400, error_code=5, error_details="Id for category not sent") categoryPtr = Category.objects.filter(id=int(category["categoryID"])) if len(categoryPtr) == 0: return customResponse(400, error_code=6, error_details="Invalid id for category sent") categoryPtr = categoryPtr[0] if not validateCategoryData(category, categoryPtr, 0): return customResponse(400, error_code=5, error_details="Invalid data for category sent") category["slug"] = slugify(category["name"]) try: if categoryPtr.show_online != int(category["show_online"]): Product.objects.filter(category_id=categoryPtr.id).update( show_online=int(category["show_online"]), updated_at=timezone.now()) populateCategoryData(categoryPtr, category) categoryPtr.save() except Exception as e: log.critical(e) closeDBConnection() return customResponse(500, error_code=3) else: closeDBConnection() return customResponse( 200, {"categories": serialize_categories(categoryPtr)})