def getAllOrders(admin_user): all_orders = Order.query.all() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return jsonify([order.toPublicDict() for order in all_orders])
def getMarketProducts(admin_user): market_products = MarketProduct.getAllProducts() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return jsonify(market_products)
def getEmailListInfo(admin_user): email_list_id = request.json.get(Labels.EmailListId) email_list_info = EmailList.getEmailListInfo(email_list_id) if not email_list_info: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = False) return JsonUtil.failure() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = True) return JsonUtil.successWithOutput({Labels.EmailList : email_list_info.toPublicDict()})
def getProductRequests(): jwt = request.json.get(Labels.Jwt) decoded_jwt = JwtUtil.decodeAdminJwt(jwt) if not decoded_jwt: AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False) return JsonUtil.jwt_failure() all_requests = Request.query.all() AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = True) return jsonify([req.toPublicDict() for req in all_requests])
def addNewEmailList(admin_user): new_email_list_name = request.json.get(Labels.NewEmailListName) matching_list = EmailList.query.filter_by(email_list_name = new_email_list_name).first() if matching_list: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = False) return JsonUtil.failure(ErrorMessages.EmailListNameTaken) EmailList.addNewEmailList(new_email_list_name) AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = True) return JsonUtil.successWithOutput()
def wrapper(): jwt = request.json.get(Labels.Jwt) admin_user = JwtUtil.decodeAdminJwt(jwt) if not admin_user: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure(ErrorMessages.InvalidCredentials) return func(admin_user)
def getHomeImages(admin_user): home_images = HomeImage.query.filter_by().all() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.successWithOutput({ Labels.Images: [home_image.toPublicDict() for home_image in home_images] })
def updateProductInfo(admin_user): product_id = request.json.get(Labels.ProductId) product = request.json.get(Labels.Product) sale_end_date = product.get('sale_end_date') print(sale_end_date) name = request.json.get(Labels.Name) tags = request.json.get(Labels.Tags) this_product = MarketProduct.query.filter_by(product_id=product_id).first() if product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("There was no input") if this_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Error retrieving product information") for key in product.keys(): try: if key in MarketProduct.INTEGER_INPUTS: if product.get(key): value = int(product.get(key)) else: value = None else: value = product.get(key) if key == Labels.ProductListingTags: tag_list = value.split(',') print(tag_list) this_product.updateProductListingTags(tag_list) if key == Labels.ProductSearchTags: tag_list = value.split(',') this_product.updateProductSearchTags(tag_list) if key == Labels.RelatedProductTags: tag_list = value.split(',') this_product.updateRelatedProductTags(tag_list) elif value != None: setattr(this_product, key, value) except: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure(key + " input is invalid") db.session.commit() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success(Labels.Product, this_product.toPublicDict())
def updateVariant(admin_user): product_id = request.json.get(Labels.ProductId) this_product = MarketProduct.query.filter_by(product_id=product_id).first() if this_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Invalid submission") variant = request.json.get(Labels.Variant) if not variant: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Invalid variant") this_variant = ProductVariant.query.filter_by( variant_id=variant[Labels.VariantId]).first() if not this_variant: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Invalid variant") this_variant.updateVariant(variant) AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success()
def uploadHomeImage(admin_user): image_data = request.json.get(Labels.ImageData) if image_data == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("No image has been uploaded!") image_bytes = image_data.encode('utf-8') image_decoded = base64.decodestring(image_bytes) HomeImage.addHomeImage(image_decoded) AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success()
def activateProduct(admin_user): product_id = request.json.get(Labels.ProductId) product = MarketProduct.query.filter_by(product_id=product_id).first() if product: product.activateProduct() else: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("product doesn't exist") AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success("Successfully activated \'" + product.name)
def getAdminMarketProductInfo(admin_user): product_id = request.json.get(Labels.ProductId) market_product = MarketProduct.query.filter_by( product_id=product_id).first() if market_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Error retrieving product information") else: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success(Labels.Product, market_product.toPublicDict())
def addMarketProduct(admin_user): market_product = request.json.get(Labels.MarketProduct) if market_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Invalid submission") name = market_product.get(Labels.Name) new_product = MarketProduct(name) db.session.add(new_product) db.session.commit() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.successWithOutput( {Labels.Product: new_product.toPublicDict()})
def addProductVariant(admin_user): product_id = request.json.get(Labels.ProductId) this_product = MarketProduct.query.filter_by(product_id=product_id).first() if this_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Invalid submission") variant_type = request.json.get(Labels.VariantType) inventory = request.json.get(Labels.Inventory) price = request.json.get(Labels.Price) this_product.addProductVariant(variant_type, price, inventory) AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.successWithOutput( {Labels.Product: this_product.toPublicDict()})
def toggleProductHasVariants(admin_user): product_id = request.json.get(Labels.ProductId) has_variants = request.json.get(Labels.HasVariants) if not product_id: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.falure("No product ID") this_product = MarketProduct.query.filter_by(product_id=product_id).first() if not this_product: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.falure("Product doesn't exist") this_product.has_variants = has_variants this_product.active = False db.session.commit() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success()
def setMainProductPhoto(admin_user): product_id = request.json.get(Labels.ProductId) image_id = request.json.get(Labels.ImageId) this_product = MarketProduct.query.filter_by(product_id=product_id).first() if this_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Error retrieving product information") this_image = ProductImage.query.filter_by(image_id=image_id).first() if this_image == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Error retrieving image") this_product.main_image = image_id db.session.commit() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success(Labels.Product, this_product.toPublicDict())
def updateHomeImage(admin_user): image_id = request.json.get(Labels.ImageId) live = request.json.get(Labels.Live) image_text = request.json.get(Labels.ImageText) if not image_id: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Bad home image input") home_image = HomeImage.query.filter_by(image_id=image_id).first() if not home_image: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Bad home image input") home_image.updateHomeImage(live, image_text) AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success()
def softDeleteProductRequestByRequestId(): jwt = request.json.get(Labels.Jwt) decoded_jwt = JwtUtil.decodeAdminJwt(jwt) if not decoded_jwt: AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False) return JsonUtil.jwt_failure() request_id = request.json.get(Labels.RequestId) if request_id == None: AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False) return JsonUtil.failure("Bad input") this_request = Request.query.filter_by(request_id = request_id).first() if this_request == None: AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = False) return JsonUtil.failure("This request id doesn't exist") this_request.soft_deleted = True db.session.commit() AdminAction.addAdminAction(decoded_jwt, request.path, request.remote_addr, success = True) return JsonUtil.success()
def uploadManufacturerLogo(admin_user): product_id = request.json.get(Labels.ProductId) image_data = request.json.get(Labels.ImageData) if image_data == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("No image has been uploaded!") image_bytes = image_data.encode('utf-8') image_decoded = base64.decodestring(image_bytes) this_product = MarketProduct.query.filter_by(product_id=product_id).first() if this_product == None: AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=False) return JsonUtil.failure("Product doesn't exist") this_product.addManufacturerLogo(image_decoded) AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success()
def getAllEmailListData(admin_user): email_list_data = EmailList.getAllEmailListData() AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success = True) return JsonUtil.successWithOutput({Labels.EmailListData : email_list_data})
def checkAdminJwt(admin_user): AdminAction.addAdminAction(admin_user, request.path, request.remote_addr, success=True) return JsonUtil.success()