当前位置: 首页>>代码示例>>Python>>正文


Python Product.put方法代码示例

本文整理汇总了Python中models.Product.put方法的典型用法代码示例。如果您正苦于以下问题:Python Product.put方法的具体用法?Python Product.put怎么用?Python Product.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Product的用法示例。


在下文中一共展示了Product.put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
 def post(self, subdomain):
     namespace_manager.set_namespace(subdomain)
     visible = False
     if self.request.get('visible') == 'yes':
         visible = True
     name = self.request.get('name')
     categories = self.request.get('category').split(',')
     logging.info(categories)
     cat_refs = []
     for category in categories:
         logging.info(category)
         if Category.get_by_key_name(category):
             cat_refs.append(Category.get_by_key_name(category).key())
     logging.info(cat_refs)
     entity = Product(key_name=name,
                       name=name,
                       shop_id=Shop.get_by_key_name(subdomain),
                       stock=int(self.request.get('qty')),
                       description=self.request.get('description'),
                       price=float(self.request.get('price')),
                       tags=self.request.get('tags').split(','),
                       video=self.request.get('video'),
                       visible=visible,
                       categories=cat_refs
                           )
     entity.put()
     self.redirect(webapp2.uri_for('addproducts'))
开发者ID:itaogit,项目名称:shopapp,代码行数:29,代码来源:admin.py

示例2: testProducts

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
    def testProducts(self):
        print ' --- Products tests -- '
        product1 = Product(name='product1', cost=1)
        product2 = Product(name='product2', cost=2)
        product3 = Product(name='product3', cost=3)

        assert product1.cost == 1
        assert product2.cost == 2
        assert product3.cost == 3

        assert product1.name == 'product1'
        assert product2.name == 'product2'
        assert product3.name == 'product3'

        product1_key = product1.put().urlsafe()
        product2_key = product2.put().urlsafe()
        product3_key = product3.put().urlsafe()

        retrieved_product1 = get_entity_memcache(product1_key)
        retrieved_product2 = get_entity_memcache(product2_key)
        retrieved_product3 = get_entity_memcache(product3_key)

        assert retrieved_product1 is not None
        assert retrieved_product2 is not None
        assert retrieved_product3 is not None

        assert retrieved_product1.name == product1.name
        assert retrieved_product2.name == product2.name
        assert retrieved_product3.name == product3.name

        assert retrieved_product1.cost == product1.cost
        assert retrieved_product2.cost == product2.cost
        assert retrieved_product3.cost == product3.cost
开发者ID:anbarquer,项目名称:gae-python-1,代码行数:35,代码来源:tests.py

示例3: setUp

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
 def setUp(self):
     self.products = []
     for i in range(1,10):
         product = Product(product_id=i, key_name="test_product_"+str(i),price=round(random.uniform(1,10),2),tax_percent=18.00)
         product.put()
         product.add_stock("test_product_"+str(i),10)
         self.products.append("test_product_"+str(i))
     self.cart = Cart()
     random.shuffle(self.products)
开发者ID:itaogit,项目名称:shopapp,代码行数:11,代码来源:tests-cart.py

示例4: create

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
def create(request, keyname):
    "Backdoor to create a new entity"
    u = auth.get_current_user(request)
    if u.is_admin:
        p = Product(key_name=keyname)
        p.name = "New Product"
        p.description = "The description"        
        p.put()
        return HttpResponseRedirect(reverse('store-edit', args=(p.key(),)))
    return HttpResponseRedirect(reverse('store-index'))
开发者ID:nicocrm,项目名称:Sailfish.Web,代码行数:12,代码来源:views.py

示例5: testAppUser

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
    def testAppUser(self, ident='123', email='[email protected]', is_admin='0'):
        print ' --- App users tests --- '
        assert not users.get_current_user()

        self.testbed.setup_env(
            USER_EMAIL=email,
            USER_ID=ident,
            USER_IS_ADMIN=is_admin,
            overwrite=True)

        user = users.get_current_user()

        assert user.email() == email
        assert user.user_id() == ident

        app_user = AppUser(identity=user.user_id(), email=user.email())
        assert app_user.identity == user.user_id()
        assert app_user.email == user.email()

        app_user_key = app_user.put().urlsafe()

        retrieved_app_user = get_entity_memcache(app_user_key)
        assert retrieved_app_user is not None
        assert retrieved_app_user.identity == user.user_id()
        assert retrieved_app_user.email == user.email()

        product1 = Product(name='product1', cost=1)
        product2 = Product(name='product2', cost=2)
        product3 = Product(name='product3', cost=3)
        product1_key = product1.put().urlsafe()
        product2_key = product2.put().urlsafe()
        product3_key = product3.put().urlsafe()

        retrieved_product1 = get_entity_memcache(product1_key)
        retrieved_product2 = get_entity_memcache(product2_key)
        retrieved_product3 = get_entity_memcache(product3_key)

        app_user.add_product(retrieved_product1)
        app_user.add_product(retrieved_product2)
        app_user.add_product(retrieved_product3)

        assert len(app_user.products) > 0
        assert len(app_user.products) == 3

        app_user.remove_product(retrieved_product1)
        assert len(app_user.products) > 0
        assert len(app_user.products) == 2

        app_user.remove_product(retrieved_product2)
        app_user.remove_product(retrieved_product3)

        assert len(app_user.products) == 0
开发者ID:anbarquer,项目名称:gae-python-1,代码行数:54,代码来源:tests.py

示例6: TestProducts

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
class TestProducts(unittest.TestCase):
    
    def setUp(self):
        self.name = random.choice('abc')
        self.product = Product(product_id=random.randint(1,10),key_name=self.name,price=random.uniform(1,10),
                          tax_percent=random.uniform(16,18))
        self.product.put()
        self.stock = random.randint(1,10)
        
        print 'TESTPRODUCTS','Product: ',self.name,' Stock: ', self.stock,
        Product().add_stock(self.name,self.stock)
    def test_reserved(self):
        qty = random.randint(1,10)
        print ' To reserve: ',qty,
        if Product.reserve(self.name,qty):
            p = Product.get_by_key_name(self.name)
            print ' AVAILABLE: ',p.available
            self.assertEqual(p.available, p.stock - qty, 'Not reserving correctly')
        else:
            p = Product.get_by_key_name(self.name)
            print ' Not enough stock', p.available
            self.assertGreater(qty, p.available, 'Not reserving correctly')
        
    def test_stocked(self):
        qty = random.randint(1,10)
    
        print ' To buy: ',qty,
        if Product.reserve(self.name,qty):
            p = Product.get_by_key_name(self.name)
            before = p.reserved
            Product.remove_stock(self.name,qty)
            p = Product.get_by_key_name(self.name)
            print ' AVAILABLE: ',p.available
            self.assertEqual(p.available, p.stock, 'Not lowering stock correctly ')
            self.assertEqual(before - qty,p.reserved, 'Not lowering reserves correctly')
        else:
            p = Product.get_by_key_name(self.name)
            print ' Not enough stock', p.available
            self.assertGreater(qty, p.available, 'Not reserving correctly')
开发者ID:itaogit,项目名称:shopapp,代码行数:41,代码来源:tests-cart.py

示例7: post

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
    def post(self):
        user = users.get_current_user()
        action = self.request.POST.get('action')
        # En la vista de productos, se envía un campo oculto llamado 'action'
        # Este campo puede tener tres valores distintos:
        # - 'create': se crea un nuevo producto aleatoriamente y se añade al listado principal de productos.
        # - 'buy': el usuario compra un nuevo producto.
        # - 'delete': se elimina un producto del listado principal.
        if action == 'create':
            product = Product(name='p' + str(random.randint(NAME_VALUES[0], NAME_VALUES[1])),
                              cost=random.randint(PRICE_VALUES[0], PRICE_VALUES[1]))
            product.put()
        elif user:
            product = Product.get_by_id(int(self.request.POST.get('id')))
            app_user = AppUser.get_or_insert(get_user_key(user),
                                             identity=user.user_id(),
                                             email=user.email())
            if action == 'buy':
                app_user.add_product(product)

            elif action == 'delete':
                app_user.remove_product(product)
                ndb.Key(Product, product.key.id()).delete()
        self.redirect(URLS['products'])
开发者ID:anbarquer,项目名称:gae-python-1,代码行数:26,代码来源:app.py

示例8: get

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import put [as 别名]
 def get(self, subdomain, item, qty):
     namespace_manager.set_namespace(subdomain)
     description = self.request.get('desc', '')
     entity = Product(key_name=item, name=item, stock=int(qty), price=10.0, tax_percent=13.0, description=description)
     entity.put()
     self.response.write('Done') 
开发者ID:itaogit,项目名称:shopapp,代码行数:8,代码来源:handlers.py


注:本文中的models.Product.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。