Exemple #1
0
def get_form_token(request):
    token = FormToken()
    token.ip = request.META.get('REMOTE_ADDR')
    token.time = time.time()
    key = common_utils.get_random_identifier(12, 'FTok')
    memcache.add(key, token, WEB_EXPIRATION_MILLISECONDS)
    return key
Exemple #2
0
def get_random_key(instance, key_length=6, prefix=''):
    while not instance.is_saved():
        key_name = get_random_identifier(key_length, prefix)
        key = db.Key.from_path(instance.__class__.kind(), key_name, parent=instance.parent_key())
        existing = db.get(key)
        if not existing: 
            instance._key_name = key_name
            instance.put()
        return