def update_product(self, request): ''' Update a product ''' product = Product.get_by_urlsafe_key(request.productKey) if not product: message = 'No product with the key "%s" exists.' % request.productKey raise endpoints.NotFoundException(message) user = User.get_by_urlsafe_key(request.userKey) if not user: message = 'No user with the key "%s" exists.' % request.userKey raise endpoints.NotFoundException(message) category = None if request.category: category = ProductCategory.get_by_urlsafe_key(request.category) price = None if request.price: price = request.price currency = CurrencyUnit.get_by_urlsafe_key(price.currencyKey) location = None if price.location: location = PhysicalLocation.load(lat=price.location.lat, lon=price.location.lon) price = Price.create(user=user, value=price.value, currency=currency, location=location) manufacturer = None if request.manufacturer: manufacturer = Manufacturer.load(name=request.manufacturer, user=user) specs = [] if request.specs: for spec in request.specs: specification = Specification.get_by_urlsafe_key(spec.key) unit = Unit.get_by_urlsafe_key(spec.unit) specs.append([specification, spec.value, unit]) product.update(user=user, name=request.name, category=category, manufacturer=manufacturer, price=price, specs=specs) return message_types.VoidMessage()
def main_parser(parser, request, id, link): product_info = parser.get_product_info(request, link) Price.create(date=date.today(), price=product_info.get('price'), product_id=id, authorized=product_info.get('is_authorise'), shop=product_info.get('shop'))