當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。