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


Python ndb.StringProperty方法代码示例

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


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

示例1: SetTaskState

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def SetTaskState(cls, task_key_id, new_state, is_aborted=True):
    """Utility method to update the state of the master task record.

    Args:
      task_key_id: String (serializable) unique id of the task record.
      new_state: String update for the ndb StringProperty field.
      is_aborted: Boolean; False when performing final update.
    """
    task = cls.GetTaskByKey(task_key_id)
    if task:
      if task.task_state != TASK_DONE:
        task.task_state = new_state
        if new_state == TASK_DONE:
          _LOG.warning('RecallTaskModel id=%s Done.', task_key_id)
      task.is_aborted = is_aborted
      task.put() 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:18,代码来源:recall_task.py

示例2: query_purchase_with_customer_key

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def query_purchase_with_customer_key():
    # [START purchase_with_customer_key_models]
    class Customer(ndb.Model):
        name = ndb.StringProperty()

    class Purchase(ndb.Model):
        customer = ndb.KeyProperty(kind=Customer)
        price = ndb.IntegerProperty()
    # [END purchase_with_customer_key_models]

    def query_purchases_for_customer_via_key(customer_entity):
        purchases = Purchase.query(
            Purchase.customer == customer_entity.key).fetch()
        return purchases

    return Customer, Purchase, query_purchases_for_customer_via_key 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:18,代码来源:snippets.py

示例3: query_purchase_with_ancestor_key

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def query_purchase_with_ancestor_key():
    # [START purchase_with_ancestor_key_models]
    class Customer(ndb.Model):
        name = ndb.StringProperty()

    class Purchase(ndb.Model):
        price = ndb.IntegerProperty()
    # [END purchase_with_ancestor_key_models]

    def create_purchase_for_customer_with_ancestor(customer_entity):
        purchase = Purchase(parent=customer_entity.key)
        return purchase

    def query_for_purchases_of_customer_with_ancestor(customer_entity):
        purchases = Purchase.query(ancestor=customer_entity.key).fetch()
        return purchases

    return (Customer, Purchase,
            create_purchase_for_customer_with_ancestor,
            query_for_purchases_of_customer_with_ancestor) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:22,代码来源:snippets.py

示例4: test_expiration

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def test_expiration(self):
    self.mock_now(datetime.datetime(2014, 1, 2, 3, 4, 5, 6))

    class Config(config.GlobalConfig):
      param = ndb.StringProperty(default='default')

    # Bootstrap the config.
    Config.cached()

    # fetch-update cycle, necessary to avoid modifying cached copy in-place.
    conf = Config.fetch()
    conf.param = 'new-value'
    conf.store(updated_by='someone')

    # Right before expiration.
    self.mock_now(datetime.datetime(2014, 1, 2, 3, 4, 5, 6), 59)
    self.assertEqual('default', Config.cached().param)

    # After expiration.
    self.mock_now(datetime.datetime(2014, 1, 2, 3, 4, 5, 6), 61)
    self.assertEqual('new-value', Config.cached().param) 
开发者ID:luci,项目名称:luci-py,代码行数:23,代码来源:config_test.py

示例5: testSameSchema

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testSameSchema(self):

    # Initial schema
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.StringProperty()

    # Create an entity using the initial schema
    inst = A(a='abc', b='def')
    inst.put()

    self.assertIsNotNone(inst.b)

    # Delete the property and save the entity
    datastore_utils.DeleteProperty(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is gone :)
    self.assertIsNone(inst.b) 
开发者ID:google,项目名称:upvote,代码行数:22,代码来源:utils_test.py

示例6: testSameSchema_DoesntDeleteProperty

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testSameSchema_DoesntDeleteProperty(self):

    # Initial schema
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.StringProperty()

    # Create an entity using the initial schema
    inst = A(a='abc', b='def')
    inst.put()

    # Delete the property and save the entity
    datastore_utils.DeleteProperty(inst, 'b')
    inst.put()

    # Create a new instance and verify that the 'b' hasn't disappeared
    new = A(a='abc', b='def')
    new.put()
    self.assertTrue(datastore_utils.HasProperty(new, 'b')) 
开发者ID:google,项目名称:upvote,代码行数:21,代码来源:utils_test.py

示例7: testSameSchema_RepeatedProperty

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testSameSchema_RepeatedProperty(self):

    # Initial schema
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.StringProperty(repeated=True)

    # Create an entity using the initial schema
    inst = A(a='abc', b=['def'])
    inst.put()

    self.assertIsNotNone(inst.b)

    # Delete the property and save the entity
    datastore_utils.DeleteProperty(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is...kinda gone :|
    self.assertEqual([], inst.b) 
开发者ID:google,项目名称:upvote,代码行数:22,代码来源:utils_test.py

示例8: testDeleteValue

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testDeleteValue(self):

    # Initial schema
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.StringProperty()

    # Create an entity using the initial schema
    inst = A(a='abc', b='def')
    inst.put()

    self.assertIsNotNone(inst.b)

    # Delete the property and save the entity
    datastore_utils.DeletePropertyValue(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is gone :)
    self.assertIsNone(inst.b) 
开发者ID:google,项目名称:upvote,代码行数:22,代码来源:utils_test.py

示例9: testDatetimeAutoNowAdd

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testDatetimeAutoNowAdd(self):

    # Initial schema
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.DateTimeProperty(auto_now_add=True)

    # Create an entity using the initial schema
    inst = A(a='abc')
    inst.put()

    # Delete the property and save the entity
    datastore_utils.DeletePropertyValue(inst, 'b')
    inst.put()

    self.assertTrue(datastore_utils.HasProperty(inst, 'b'))
    self.assertIsNotNone(inst.b) 
开发者ID:google,项目名称:upvote,代码行数:19,代码来源:utils_test.py

示例10: testRepeatedProperty

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testRepeatedProperty(self):

    # Initial schema
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.StringProperty(repeated=True)

    # Create an entity using the initial schema
    inst = A(a='abc', b=['def'])
    inst.put()

    self.assertIsNotNone(inst.b)

    # Delete the property and save the entity
    datastore_utils.DeletePropertyValue(inst, 'b')
    inst.put()
    inst = A.get_by_id(inst.key.id())

    # The old data is gone
    self.assertEqual([], inst.b) 
开发者ID:google,项目名称:upvote,代码行数:22,代码来源:utils_test.py

示例11: testRequiredField

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testRequiredField(self):

    # Initial schema but this time with a required property
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.StringProperty(required=True)

    # Create an entity using the initial schema
    inst = A(a='abc', b='def')
    inst.put()

    # Delete the property and save the entity
    datastore_utils.DeletePropertyValue(inst, 'b')
    # Property required but no longer has a value.
    with self.assertRaises(Exception):
      inst.put() 
开发者ID:google,项目名称:upvote,代码行数:18,代码来源:utils_test.py

示例12: testHasValue

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testHasValue(self):

    class Foo(ndb.Model):
      a = ndb.ComputedProperty(lambda self: 'a')
      b = ndb.StringProperty()

    foo = Foo()
    self.assertFalse(datastore_utils.HasValue(foo, 'a'))
    self.assertFalse(datastore_utils.HasValue(foo, 'b'))

    foo.b = 'b'
    self.assertFalse(datastore_utils.HasValue(foo, 'a'))
    self.assertTrue(datastore_utils.HasValue(foo, 'b'))

    foo.put()
    self.assertTrue(datastore_utils.HasValue(foo, 'a'))
    self.assertTrue(datastore_utils.HasValue(foo, 'b')) 
开发者ID:google,项目名称:upvote,代码行数:19,代码来源:utils_test.py

示例13: testQueryModel_TranslatePropertyQuery

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def testQueryModel_TranslatePropertyQuery(self):
    class Foo(ndb.Model):
      foo = ndb.StringProperty()

      @classmethod
      def TranslatePropertyQuery(cls, field, term):
        return 'foo', 'bar'

    class FooQueryHandler(handler_utils.UserFacingQueryHandler):
      MODEL_CLASS = Foo

    # Request a nonsense query to be ignored by TranslatePropertyQuery.
    with self.LoggedInUser():
      q = FooQueryHandler()._QueryModel({'bar': 'baz'})
    # Create an entity satisfying the translated query.
    Foo(foo='bar').put()
    # Ensure the translated query finds the created entity.
    self.assertIsNotNone(q.get()) 
开发者ID:google,项目名称:upvote,代码行数:20,代码来源:handler_utils_test.py

示例14: test_generate_entity_schema

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def test_generate_entity_schema(self):

    class NestedTestModel(ndb.Model):
      nested_string_attribute = ndb.StringProperty()

    class TestModel(ndb.Model):
      string_attribute = ndb.StringProperty()
      integer_attribute = ndb.IntegerProperty()
      boolean_attribute = ndb.BooleanProperty()
      nested_attribute = ndb.StructuredProperty(NestedTestModel)

    schema = bigquery._generate_entity_schema(TestModel())
    expected_schema_names = _populate_schema_names(self.entity_schema)
    schema_names = _populate_schema_names(schema)
    self.assertCountEqual(expected_schema_names, schema_names) 
开发者ID:google,项目名称:loaner,代码行数:17,代码来源:bigquery_test.py

示例15: get_TextField

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import StringProperty [as 别名]
def get_TextField(kwargs):
    """
    Returns a ``TextField``, applying the ``ndb.StringProperty`` length limit
    of 500 bytes.
    """
    kwargs['validators'].append(validators.length(max=500))
    return f.TextField(**kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:ndb.py


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