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


Python Key.from_path方法代码示例

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


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

示例1: createPlayer

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_given_score_and_TwoDisapprovingButNonAgreeingReviewerAndOneApprovingReviewer_then_NonApprovingReviewerAreCheater_and_playerVerifiedScoreIsUpdated(self):
        score = {'score' : 3, 'proof' : "sdsd", 'time' : 0}
        playerId = "test"
        createPlayer(playerId, playerId)
        service.start(playerId)
        service.setScore(playerId, score)

        playerKey = Key.from_path('Player', playerId)
        createReviewerAndReview("test2", playerKey, {'score':99, 'time': 0})

        createReviewerAndReview("test3", playerKey, {'score':999, 'time': 0})

        createReviewerAndReview("test4", playerKey, {'score':3, 'time': 0})

        verifiedScoreWrapper = VerifiedScoreWrapper.get_by_key_name('verifiedScore', parent=playerKey)
        verifiedScore = verifiedScoreWrapper.verified
        self.assertEqual(verifiedScore.value, 3)

        playerKey = Key.from_path('Player', 'test2')
        playerRecord = Record.get_by_key_name('record', parent=playerKey)
        self.assertEqual(playerRecord.numCheat, 1)

        playerKey = Key.from_path('Player', 'test3')
        playerRecord = Record.get_by_key_name('record', parent=playerKey)
        self.assertEqual(playerRecord.numCheat, 1)
开发者ID:wighawag,项目名称:ubh,代码行数:27,代码来源:testScore.py

示例2: setReviewTimeUnit

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_given_aAdminReviewerTryingToReviewAsAdmin_ItShouldSucceedAndDeclareNonAgreeingConflictingReviewerAsCheaters(self):

        setReviewTimeUnit(0)
        score = {'score' : 99, 'proof' : "sdsd", 'time' : 0}
        playerId = "test"
        createPlayer(playerId, playerId)
        service.start(playerId)
        service.setScore(playerId, score)

        playerKey = Key.from_path('Player', playerId)

        createReviewerAndReview("test2", playerKey, {'score':3, 'time': 0})

        createReviewerAndReview("test3", playerKey, {'score':999, 'time': 0})

        createReviewerAndReview("test4", playerKey, {'score':3, 'time': 0}, True)


        verifiedScore = VerifiedScore.get_by_key_name("verified", parent=playerKey)
        playerRecord = Record.get_by_key_name('record', parent=playerKey)

        self.assertTrue(verifiedScore is None or verifiedScore.value == 0)
        self.assertEqual(playerRecord.numCheat, 1)


        playerKey = Key.from_path('Player', 'test3')
        playerRecord = Record.get_by_key_name('record', parent=playerKey)
        self.assertEqual(playerRecord.numCheat, 1)

        playerKey = Key.from_path('Player', 'test2')
        playerRecord = Record.get_by_key_name('record', parent=playerKey)
        self.assertEqual(playerRecord.numCheat, 0)
开发者ID:wighawag,项目名称:ubh,代码行数:34,代码来源:testScore.py

示例3: test_key_kind

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_key_kind(self):
        """
        Checks that db.Keys stored in the database use proper kinds.

        Key kind should be the name of the table (db_table) of a model
        for primary keys of entities, but for foreign keys, references
        in general, it should be the db_table of the model the field
        refers to.

        Note that Django hides the underlying db.Key objects well, and
        it does work even with wrong kinds, but keeping the data
        consistent may be significant for external tools.

        TODO: Add DictField / EmbeddedModelField and nesting checks.
        """
        parent = ParentKind.objects.create(pk=1)
        child = ChildKind.objects.create(
            pk=2, parent=parent, parents=[parent.pk])
        self.assertEqual(child.parent.pk, parent.pk)
        self.assertEqual(child.parents[0], parent.pk)

        from google.appengine.api.datastore import Get
        from google.appengine.api.datastore_types import Key
        parent_key = Key.from_path(parent._meta.db_table, 1)
        child_key = Key.from_path(child._meta.db_table, 2)
        parent_entity = Get(parent_key)
        child_entity = Get(child_key)
        parent_column = child._meta.get_field('parent').column
        parents_column = child._meta.get_field('parents').column
        self.assertEqual(child_entity[parent_column], parent_key)
        self.assertEqual(child_entity[parents_column][0], parent_key)
开发者ID:3quarterstack,项目名称:simple_blog,代码行数:33,代码来源:test_keys.py

示例4: test_newPlayerWithoutReviewAssigned_shouldGetNoReviews

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_newPlayerWithoutReviewAssigned_shouldGetNoReviews(self):
        playerId = "test"
        createPlayer(playerId, playerId)

        playerKey = Key.from_path('Player', playerId)
        reviewSession = ReviewSession.get_by_key_name('reviewSession', parent=playerKey)
        self.assertEqual(reviewSession, None)
开发者ID:wighawag,项目名称:ubh,代码行数:9,代码来源:testScore.py

示例5: test_given_aAdminReviewerTryingToReviewAsAdmin_ItShouldSucceed

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_given_aAdminReviewerTryingToReviewAsAdmin_ItShouldSucceed(self):

        setReviewTimeUnit(0)
        score = {'score' : 3, 'proof' : "sdsd", 'time' : 0}
        playerId = "test1"
        createPlayer(playerId, playerId)
        service.start(playerId)
        service.setScore(playerId, score)

        createPlayer("reviewer1", "reviewer1")

        admin = getAdmin()
        admin.playerList.append('reviewer1')
        setAdmin(admin)

        service.getRandomScore("reviewer1")
        response = service.reviewScore("reviewer1", {'score':3, 'time': 0}, True)


        self.assertTrue('result' in response)

        playerKey = Key.from_path('Player', playerId)
        verifiedScoreWrapper = VerifiedScoreWrapper.get_by_key_name('verifiedScore', parent=playerKey)
        verifiedScore = verifiedScoreWrapper.verified
        self.assertEqual(verifiedScore.value, 3)
        self.assertEqual(verifiedScore.approvedByAdmin, True)
开发者ID:wighawag,项目名称:ubh,代码行数:28,代码来源:testScore.py

示例6: __init__

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
 def __init__(
     self,
     left,
     op=None,
     right=None,
     ):
     self.get_all =  self.get_one = None
     if isinstance(left, list):
         self.filters = left
         return
     if isinstance(right, (Field, Expression)):
         raise SyntaxError, \
             'Query: right side of filter must be a value or entity: %s' \
             % right
     if isinstance(left, Field):
         # normal filter: field op value
         assert_filter_fields(left)
         if left.type == 'id':
             try:
                 if type(right) == list:
                     #make this work for belongs
                     right = [long(r) for r in right]
                 else:
                     right = long(right or 0)
             except ValueError:
                 raise SyntaxError, 'id value must be integer: %s' % id
             if op != '=' and not (op == '>' and right == 0):
                 #get key (or keys) based on path.  Note if we later support
                 # ancesters this will not be the proper key for items with
                 # ancesters.
                 #in GAE (with no ancesters) the key is base64 encoded
                 # "table_name: id=<id>".  GAE decodes the string and compares
                 # the id
                 if op=='IN':
                     right = [Key.from_path(left._tablename, r) for r in right]
                 else:
                     right = Key.from_path(left._tablename, right)
         elif op=='IN':
             right = [dateobj_to_datetime(obj_represent(r, left.type, left._db)) \
                          for r in right]
         else:
             # filter dates/times need to be datetimes for GAE
             right = dateobj_to_datetime(obj_represent(right, left.type, left._db))
         self.filters = [Filter(left, op, right)]
         return
     raise SyntaxError, 'not supported'
开发者ID:BlackgateResearch,项目名称:Pip-Target,代码行数:48,代码来源:gql.py

示例7: setUser_MakerSecret

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def setUser_MakerSecret(id, maker_secret):
    key = Key.from_path('UserData', id)
    entity = datastore.Get(key)
    entity.update({
        'maker_secret': maker_secret

    })
    datastore.Put(entity)
    memcache.set(key="MakerSecret-" + id, value=maker_secret)
开发者ID:MypaceEngine,项目名称:ifttt-line,代码行数:11,代码来源:userinfo_utility.py

示例8: test_db_conversion

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_db_conversion(self):
        actual_datetime = datetime.datetime.now()
        entity = FieldsWithoutOptionsModel(
            datetime=actual_datetime, date=actual_datetime.date(),
            time=actual_datetime.time(), floating_point=5.97, boolean=True,
            null_boolean=False, text='Hallo', email='[email protected]',
            comma_seperated_integer='5,4,3,2',
            ip_address='194.167.1.1', slug='you slugy slut :)',
            url='http://www.scholardocs.com', long_text=1000 * 'A',
            indexed_text='hello',
            integer=-400, small_integer=-4, positive_integer=400,
            positive_small_integer=4)
        entity.save()

        # Get the gae entity (not the django model instance) and test
        # if the fields have been converted right to the corresponding
        # GAE database types.
        gae_entity = Get(
            Key.from_path(FieldsWithoutOptionsModel._meta.db_table,
            entity.pk))
        opts = FieldsWithoutOptionsModel._meta
        for name, types in [('long_text', Text),
                ('indexed_text', unicode),
                ('text', unicode), ('ip_address', unicode), ('slug', unicode),
                ('email', unicode), ('comma_seperated_integer', unicode),
                ('url', unicode), ('time', datetime.datetime),
                ('datetime', datetime.datetime), ('date', datetime.datetime),
                ('floating_point', float), ('boolean', bool),
                ('null_boolean', bool), ('integer', (int, long)),
                ('small_integer', (int, long)),
                ('positive_integer', (int, long)),
                ('positive_small_integer', (int, long))]:
            column = opts.get_field_by_name(name)[0].column
            if not isinstance(types, (list, tuple)):
                types = (types, )
            self.assertTrue(type(gae_entity[column]) in types)

        # Get the model instance and check if the fields convert back
        # to the right types.
        model = FieldsWithoutOptionsModel.objects.get()
        for name, types in [
                ('long_text', unicode),
                ('indexed_text', unicode),
                ('text', unicode), ('ip_address', unicode),
                ('slug', unicode),
                ('email', unicode), ('comma_seperated_integer', unicode),
                ('url', unicode), ('datetime', datetime.datetime),
                ('date', datetime.date), ('time', datetime.time),
                ('floating_point', float), ('boolean', bool),
                ('null_boolean', bool), ('integer', (int, long)),
                ('small_integer', (int, long)),
                ('positive_integer', (int, long)),
                ('positive_small_integer', (int, long))]:
            if not isinstance(types, (list, tuple)):
                types = (types, )
            self.assertTrue(type(getattr(model, name)) in types)
开发者ID:3quarterstack,项目名称:simple_blog,代码行数:58,代码来源:test_field_db_conversion.py

示例9: key_from_path

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def key_from_path(db_table, value):
    """
    Workaround for GAE choosing not to validate integer ids when
    creating keys.

    TODO: Should be removed if it gets fixed.
    """
    if isinstance(value, (int, long)):
        ValidateInteger(value, 'id')
    return Key.from_path(db_table, value)
开发者ID:jmgallego,项目名称:potato_blog,代码行数:12,代码来源:base.py

示例10: test_given_aScoreSubmitedTooEarly_ItShouldNotBeSubmited

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
    def test_given_aScoreSubmitedTooEarly_ItShouldNotBeSubmited(self):
        score = {'score' : 3, 'proof' : "sdsd", 'time' : 10000}
        playerId = "test"
        createPlayer(playerId, playerId)
        service.start(playerId)
        service.setScore(playerId, score)

        playerKey = Key.from_path('Player', playerId)
        pendingScore = PendingScore.get_by_key_name('pendingScore', parent=playerKey)
        self.assertEqual(pendingScore, None)
开发者ID:wighawag,项目名称:ubh,代码行数:12,代码来源:testScore.py

示例11: getUser_MakerSecret

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def getUser_MakerSecret(id):
    secret = memcache.get(key="MakerSecret-" + id)
    if secret == None:
        try:
            key = Key.from_path('UserData', id)
            entity = datastore.Get(key)
            secret = entity['maker_secret']
            memcache.set(key="MakerSecret-" + id, value=secret)
        except:
            logging.debug(id + u"のIFTTT Maker Secretは登録されていません。")
    return secret
开发者ID:MypaceEngine,项目名称:ifttt-line,代码行数:13,代码来源:userinfo_utility.py

示例12: deleteUserData

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def deleteUserData(id):
    # memcache.delete(key="MakerSecret-"+id)
    # memcache.delete(key="USER-"+id)
    # dashid=memcache.get(key="User-dash-"+id)
    # memcache.delete(key = "User-dash-"+id)
    # memcache.delete(key = "Dash-user-"+str(dashid))

    try:
        key = Key.from_path('UserData', id)
        entity = datastore.Delete(key)
    except:
        logging.debug(id + u"は登録されていません。")
开发者ID:MypaceEngine,项目名称:ifttt-line,代码行数:14,代码来源:userinfo_utility.py

示例13: key_from_path

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def key_from_path(db_table, value):
    """
    Workaround for GAE choosing not to validate integer ids when
    creating keys.

    TODO: Should be removed if it gets fixed.
    """

    from google.appengine.api.datastore_types import Key, ValidateInteger

    if isinstance(value, (int, long)):
        ValidateInteger(value, 'id')
    return Key.from_path(db_table, value)
开发者ID:olibrook,项目名称:djangae,代码行数:15,代码来源:base.py

示例14: test_getLineIdFromId

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def test_getLineIdFromId(id):
    result = 'dummy'
    # return result
    try:
        key = Key.from_path('UserData', id)
        entity = datastore.Get(key)
        if entity != None:
            result = entity['lineId']
        else:
            logging.debug(id + u"は登録されていません。")
    except:
        logging.debug(id + u"は登録されていません。")

    return result
开发者ID:MypaceEngine,项目名称:ifttt-line,代码行数:16,代码来源:userinfo_utility.py

示例15: isExistUserData

# 需要导入模块: from google.appengine.api.datastore_types import Key [as 别名]
# 或者: from google.appengine.api.datastore_types.Key import from_path [as 别名]
def isExistUserData(lineId):
    id = lineId
    result = False
    try:
        key = Key.from_path('UserData', id)
        entity = datastore.Get(key)
        if entity != None:
            result = True
        else:
            logging.debug(id + u"は登録されていません。")
    except:
        logging.debug(id + u"は登録されていません。")

    return result
开发者ID:MypaceEngine,项目名称:ifttt-line,代码行数:16,代码来源:userinfo_utility.py


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