def getAllProducts(**kwargs): ''' Returns all the product. ''' product = ProductModel() productData = product.getAllProducts() products = [] if productData != None: for p in productData: productTemp = {} productTemp["id"] = p.id productTemp["name"] = p.name productTemp["sku"] = p.sku productTemp["description"] = p.description productTemp["active"] = p.active products.append(productTemp) if kwargs['active'] != None: products = list( filter(lambda x: str(x['active']).lower() == kwargs['active'], products)) elif kwargs['name'] != None: products = list( filter(lambda x: x['name'] == kwargs['name'], products)) elif kwargs['sku'] != None: products = list( filter(lambda x: x['sku'] == kwargs['sku'], products)) elif kwargs['limit'] != None: products = products[0:int(kwargs['limit'])] return SuccessResponse.sendResponse( SuccessResponse.constants['PRODUCT_DATA'], products)
def get_all(category=None): print category if category: if category == 'POSSOCOMPRAR': user_logged = session['barzinga_user'] user = User.query().filter( User.email == user_logged["email"]).get() products = [ p.to_dict() for p in Product.query(Product.price <= user.money).order( Product.description).fetch() ] else: products = [ p.to_dict() for p in Product.query(Product.category == category).order( Product.description).fetch() ] else: products = [ p.to_dict() for p in Product.query().order(Product.description).fetch() ] return json.dumps(products)
async def addProduct(self, **kwargs): """ Async function to add product in the database parameters: **kwargs - names arguments name, sku, description returns: confirmation of adding """ name = kwargs['name'] sku = kwargs['sku'] id = str(uuid.uuid4()) description = kwargs['description'] active = kwargs['active'] if kwargs['active'] == None: active = random.choice([True, False]) product = ProductModel() productData = product.getProductBySku(sku) if productData == None: return product.insertProduct( id=id, description=description, sku=sku, name=name, active=active) else: return product.updateProduct(sku, name=name, description=description)
def get_all(category=None): if category: query = Product.query().filter(Product.category == category) else: query = Product.query() products = [ p.to_dict() for p in query.filter( Product.active == True).order(Product.description).fetch() ] return json.dumps(products)
def deleteProduct(id): """ Delete the product for an id parameters: string:id - id of the product returns: string:success response """ product = ProductModel() product.deleteProduct(id) return SuccessResponse.sendResponse( SuccessResponse.constants['PRODUCT_DATA_DELETED'], {})
def upload_product_images( protecode_cfg_name: str, product_cfg_file: CliHints.existing_file(), processing_mode: CliHint( choices=list(ProcessingMode), type=ProcessingMode, ) = ProcessingMode.UPLOAD_IF_CHANGED, protecode_group_id: int = 5, parallel_jobs: int = 4, cve_threshold: int = 7, ignore_if_triaged: bool = True, reference_group_ids: [int] = [], ): cfg_factory = ctx().cfg_factory() protecode_cfg = cfg_factory.protecode(protecode_cfg_name) product_descriptor = Product.from_dict( raw_dict=parse_yaml_file(product_cfg_file)) upload_images( protecode_cfg=protecode_cfg, product_descriptor=product_descriptor, protecode_group_id=protecode_group_id, parallel_jobs=parallel_jobs, cve_threshold=cve_threshold, ignore_if_triaged=ignore_if_triaged, processing_mode=processing_mode, reference_group_ids=reference_group_ids, )
def repryce(product_id): product = Product.get_by_id(product_id) product.price = float(request.form['price']) product.put() return '', 204
def add_quantity(product_id): product = Product.get_by_id(product_id) product.quantity += int(request.form['quantity']) product.put() return '', 204
def get_by_id(product_id): product = Product.get_by_id(product_id) if not product: return 'Product id %s not found' % (product_id), 404 return json.dumps(product.to_dict())
def update_bar_code(product_id): product = Product.get_by_id(product_id) product.bar_code = str(request.form['bar_code']) product.put() return '', 204
def delete(product_id): product = Product.get_by_id(product_id) if not product: return 'Product id %s not found' % (product_id), 404 product.key.delete() return '', 204
def _enumerate_images( component_descriptor: Product, image_reference_filter=lambda _: True, ): for component in component_descriptor.components(): component_dependencies = component.dependencies() for container_image in filter( image_reference_filter, component_dependencies.container_images()): yield (component, container_image)
def add(): user_logged = session['barzinga_user'] user_operator = User.query().filter( User.email == user_logged["email"]).get() if user_operator.admin: bucket_name = os.environ.get( 'BUCKET_NAME', app_identity.get_default_gcs_bucket_name()) description = request.form['description'] category = request.form['category'] price = float(request.form['price']) quantity = int(request.form['quantity']) image = request.files['image'] image_url = None if image: write_retry_params = gcs.RetryParams(backoff_factor=1.1) filename = '/' + bucket_name + '/' + image.filename gcs_file = gcs.open(filename, 'w', content_type=image.content_type, retry_params=write_retry_params) gcs_file.write(image.read()) gcs_file.close() blobstore_filename = '/gs' + filename key = blobstore.create_gs_key(blobstore_filename) image_url = get_serving_url(key) product = Product(description=description, price=price, quantity=quantity, category=category, image_url=image_url, bar_code=str(''), active=True) product.put() return '', 204 else: return 'Precisa ser admin para cadastrar produtos', 401
def compra(product_id): product = Product.get_by_id(product_id) if not product: return 'Product id %s not found' % (product_id), 404 product.price = float(request.form['price']) product.quantity += int(request.form['quantity']) product.put() return '', 204
def resolve_component_descriptor( component_descriptor_file: CliHints.existing_file(), ): cfg_factory = ctx().cfg_factory() resolver = ComponentDescriptorResolver(cfg_factory=cfg_factory, ) with open(component_descriptor_file) as f: component_descriptor = Product.from_dict(yaml.load(f)) resolved_descriptor = resolver.resolve_component_references( product=component_descriptor) print(yaml.dump(resolved_descriptor.raw))
def component_descriptor_to_xml( component_descriptor: CliHints.existing_file(), out_file: str, ): component_descriptor = Product.from_dict( parse_yaml_file(component_descriptor)) def images(component_descriptor): for component in component_descriptor.components(): yield from component.dependencies().container_images() result_xml = product.xml.container_image_refs_to_xml( container_images=images(component_descriptor), ) result_xml.write(out_file)
def getProduct(id): """ Returns the product details for an id parameters: string:id - id of the product returns: string:success response """ product = ProductModel() productData = product.getProduct(id) if productData != None: return SuccessResponse.sendResponse( SuccessResponse.constants['PRODUCT_DATA'], { "id": productData.id, "name": productData.name, "sku": productData.sku, "description": productData.description, 'active': productData.active }) else: return ErrorResponse.sendResponse( ErrorResponse.constants['PRODUCT_NOT_EXIST'])
def modify(product_id): product = Product.get_by_id(product_id) if not product: return 'Product id %s not found' % (product_id), 404 try: product.description = request.form['description'] product.price = float(request.form['price']) product.quantity = int(request.form['quantity']) product.put() except: return 'Deu ruim merm\u00E3o', 400 return '', 204
def add_dependencies( descriptor_src_file: CliHints.existing_file(), component_name: str, component_version: str, descriptor_out_file: str = None, component_dependencies: CliHint(typehint=_parse_component_deps, action='append') = [], container_image_dependencies: CliHint(typehint=_parse_container_image_deps, action='append') = [], web_dependencies: CliHint(typehint=_parse_web_deps, action='append') = [], generic_dependencies: CliHint(typehint=_parse_generic_deps, action='append') = [], ): product = Product.from_dict(parse_yaml_file(descriptor_src_file)) component = product.component( ComponentReference.create(name=component_name, version=component_version)) if not component: fail('component {c}:{v} was not found in {f}'.format( c=component_name, v=component_version, f=descriptor_src_file)) component_deps = component.dependencies() for component_ref in component_dependencies: component_deps.add_component_dependency(component_ref) for image_dep in container_image_dependencies: component_deps.add_container_image_dependency(image_dep) for web_dep in web_dependencies: component_deps.add_web_dependency(web_dep) for generic_dep in generic_dependencies: component_deps.add_generic_dependency(generic_dep) product_dict = json.loads(json.dumps({'components': [component.raw]})) if not descriptor_out_file: print(yaml.dump(product_dict, indent=2)) else: with open(descriptor_out_file, 'w') as f: yaml.dump(product_dict, f, indent=2)
from product.model import Product products_data = [ Product('Salt', '001', 540, "Salt Sal Sol"), Product('Flour', '002', 780, "Dona Arepa"), Product('Sugar', '003', 780, "Sugar") ]
def create_product(incoming_data: dict): new_product = Product(incoming_data.get("name"), incoming_data.get("code"), incoming_data.get("price"), incoming_data.get("description")) products_data.append(new_product)
def deleteAllProduct(): ''' Delete all the product. ''' product = ProductModel() product.deleteAllProducts() return SuccessResponse.sendResponse( SuccessResponse.constants['PRODUCT_DATA_DELETED'], {})
def delete_product(product_id: str) -> bool: lookup_product = Product("", product_id, 0, "") if lookup_product in products_data: products_data.remove(lookup_product) return True return False
offset=(1.4, -1.4), drift=(0.9, -0.9), customer_criteria=high_end_criteria, name="High End") size = MarketSegment(starting_point=(3, 12), offset=(1.0, -1.4), drift=(0.7, -1.0), customer_criteria=size_criteria, name="Size") market_segments = [low_end, traditional, high_end, performance, size] # Create products cake = Product("Cake", performance=5.6, size=14.5, mtbf=17500, year=0, num_years=NUM_YEARS) cedar = Product("Cedar", performance=3.0, size=17.0, mtbf=14000, year=0, num_years=NUM_YEARS) cid = Product("Cid", performance=8.0, size=11.9, mtbf=23000, year=0, num_years=NUM_YEARS) coat = Product("Coat",
def getProductCount(): ''' Returns the Number of Product in database. ''' product = ProductModel() count = product.productCount() return SuccessResponse.sendResponse( SuccessResponse.constants['PRODUCT_DATA'], count)
def parse_product_file(f): return Product.from_dict(parse_yaml_file(f))