當前位置: 首頁>>代碼示例>>Python>>正文


Python ndb.ComputedProperty方法代碼示例

本文整理匯總了Python中google.appengine.ext.ndb.ComputedProperty方法的典型用法代碼示例。如果您正苦於以下問題:Python ndb.ComputedProperty方法的具體用法?Python ndb.ComputedProperty怎麽用?Python ndb.ComputedProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.ComputedProperty方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: need_update_from_run_result

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def need_update_from_run_result(self, run_result):
    """Returns True if set_from_run_result() would modify this instance.

    E.g. they are different and TaskResultSummary needs to be updated from the
    corresponding TaskRunResult.
    """
    assert isinstance(run_result, TaskRunResult), run_result
    # A previous try is still sending update. Ignore it from a result summary
    # PoV.
    if self.try_number and self.try_number > run_result.try_number:
      return False

    for property_name in _TaskResultCommon._properties_fixed():
      if getattr(self, property_name) != getattr(run_result, property_name):
        return True
    # Include explicit support for 'state' and 'try_number'. TaskRunResult.state
    # is a ComputedProperty so it can't be copied as-is, and try_number is a
    # generated property.
    # pylint: disable=W0201
    return (
        self.state != run_result.state or
        self.try_number != run_result.try_number) 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:task_result.py

示例2: testHasValue

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [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

示例3: GetLocalComputedPropertyValue

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def GetLocalComputedPropertyValue(entity, computed_property_name):
  """Return the local value of a ComputedProperty instead of re-computing.

  Args:
    entity: ndb.Model, The entity from which the ComputedProperty will be read.
    computed_property_name: str, The name of the ComputedProperty whose value
        will be read.

  Returns:
    The local value of the property.

  Raises:
    PropertyError: The property was not found or was not a ComputedProperty.
  """
  computed_property = entity._properties.get(computed_property_name, None)  # pylint: disable=protected-access
  if not computed_property:
    raise PropertyError('Property %s not found' % computed_property_name)
  elif not isinstance(computed_property, ndb.ComputedProperty):
    raise PropertyError(
        'Property %s is of type %s. Expected ComputedProperty.' % (
            computed_property_name, type(entity).__name__))
  return super(  # pylint: disable=protected-access
      ndb.ComputedProperty, computed_property)._get_value(entity) 
開發者ID:google,項目名稱:upvote,代碼行數:25,代碼來源:utils.py

示例4: convert_ComputedProperty

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def convert_ComputedProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.ComputedProperty``."""
        return None 
開發者ID:jpush,項目名稱:jbox,代碼行數:5,代碼來源:ndb.py

示例5: _properties_fixed

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def _properties_fixed(cls):
    """Returns all properties with their member name, excluding computed
    properties.
    """
    return [
      prop._code_name for prop in cls._properties.values()
      if not isinstance(prop, ndb.ComputedProperty)
    ] 
開發者ID:luci,項目名稱:luci-py,代碼行數:10,代碼來源:task_result.py

示例6: set_from_run_result

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def set_from_run_result(self, run_result, request):
    """Copies all the relevant properties from a TaskRunResult into this
    TaskResultSummary.

    If the task completed, succeeded and is idempotent, self.properties_hash is
    set.
    """
    assert ndb.in_transaction()
    assert isinstance(request, task_request.TaskRequest), request
    assert isinstance(run_result, TaskRunResult), run_result
    for property_name in _TaskResultCommon._properties_fixed():
      setattr(self, property_name, getattr(run_result, property_name))
    # Include explicit support for 'state' and 'try_number'. TaskRunResult.state
    # is a ComputedProperty so it can't be copied as-is, and try_number is a
    # generated property.
    # pylint: disable=W0201
    self.state = run_result.state
    self.try_number = run_result.try_number

    while len(self.costs_usd) < run_result.try_number:
      self.costs_usd.append(0.)
    self.costs_usd[run_result.try_number-1] = run_result.cost_usd

    # Update the automatic tags, removing the ones from the other
    # TaskProperties.
    t = request.task_slice(run_result.current_task_slice or 0)
    if run_result.current_task_slice != self.current_task_slice:
      self.tags = task_request.get_automatic_tags(
          request, run_result.current_task_slice)
    if (self.state == State.COMPLETED and
        not self.failure and
        not self.internal_failure and
        t.properties.idempotent and
        not self.deduped_from):
      # Signal the results are valid and can be reused. If the request has a
      # SecretBytes, it is GET, which is a performance concern.
      self.properties_hash = t.properties_hash(request) 
開發者ID:luci,項目名稱:luci-py,代碼行數:39,代碼來源:task_result.py

示例7: _validate_filters_ndb

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def _validate_filters_ndb(cls, filters, model_class):
    """Validate ndb.Model filters."""
    if not filters:
      return

    properties = model_class._properties


    for idx, f in enumerate(filters):
      prop, ineq, val = f
      if prop not in properties:
        raise errors.BadReaderParamsError(
            "Property %s is not defined for entity type %s",
            prop, model_class._get_kind())

      # Attempt to cast the value to a KeyProperty if appropriate.
      # This enables filtering against keys.
      try:
        if (isinstance(val, basestring) and
            isinstance(properties[prop],
              (ndb.KeyProperty, ndb.ComputedProperty))):
          val = ndb.Key(urlsafe=val)
          filters[idx] = [prop, ineq, val]
      except:
        pass

      # Validate the value of each filter. We need to know filters have
      # valid value to carry out splits.
      try:
        properties[prop]._do_validate(val)
      except db.BadValueError, e:
        raise errors.BadReaderParamsError(e) 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-mapreduce,代碼行數:34,代碼來源:input_readers.py

示例8: testFailToSet_ComputedProperty

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def testFailToSet_ComputedProperty(self):
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.ComputedProperty(lambda self: self.a[0])

    inst = A(a='xyz')
    inst.put()

    self.assertEqual('x', inst.b)

    with self.assertRaises(datastore_utils.PropertyError):
      datastore_utils.CopyEntity(inst, b='a') 
開發者ID:google,項目名稱:upvote,代碼行數:14,代碼來源:utils_test.py

示例9: testModelWithComputedProperty

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def testModelWithComputedProperty(self):
    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.ComputedProperty(lambda self: self.a[0])

    inst = A(a='xyz')
    inst.put()

    self.assertEqual('x', inst.b)

    new = datastore_utils.CopyEntity(inst, a='abc')
    new.put()

    self.assertEqual('a', new.b) 
開發者ID:google,項目名稱:upvote,代碼行數:16,代碼來源:utils_test.py

示例10: setUp

# 需要導入模塊: from google.appengine.ext import ndb [as 別名]
# 或者: from google.appengine.ext.ndb import ComputedProperty [as 別名]
def setUp(self):
    super(GetLocalComputedPropertyValueTest, self).setUp()

    class A(ndb.Model):
      a = ndb.StringProperty()
      b = ndb.ComputedProperty(lambda self: self.a[0])

    self.inst = A(a='xyz') 
開發者ID:google,項目名稱:upvote,代碼行數:10,代碼來源:utils_test.py


注:本文中的google.appengine.ext.ndb.ComputedProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。