本文整理汇总了Python中storymap.storage.key_name函数的典型用法代码示例。如果您正苦于以下问题:Python key_name函数的具体用法?Python key_name怎么用?Python key_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了key_name函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: storymap_migrate
def storymap_migrate(user):
"""
Migrate a storymap
@title = storymap title
@url = storymap base url
@draft_on = ...
@published_on = ...
@file_list = json encoded list of file names
"""
try:
title, src_url, draft_on, file_list_json = _request_get_required(
'title', 'url', 'draft_on', 'file_list')
published_on = _request_get('published_on')
file_list = json.loads(file_list_json)
dst_id = _make_storymap_id(user, title)
dst_key_prefix = storage.key_prefix(user['uid'], dst_id)
dst_url = settings.AWS_STORAGE_BUCKET_URL+dst_key_prefix
dst_img_url = dst_url+'_images/'
re_img = re.compile(r'.*\.(png|gif|jpg|jpeg)$', re.I)
re_src = re.compile(r'%s' % src_url)
for file_name in file_list:
file_url = "%s%s" % (src_url, file_name)
if file_name.endswith('.json'):
key_name = storage.key_name(user['uid'], dst_id, file_name)
r = requests.get(file_url)
storage.save_json(key_name, re_src.sub(dst_img_url, r.text))
elif re_img.match(file_name):
key_name = storage.key_name(user['uid'], dst_id, '_images', file_name)
storage.save_from_url(key_name, file_url)
else:
continue # skip
user['storymaps'][dst_id] = {
'id': dst_id,
'title': title,
'draft_on': draft_on,
'published_on': published_on
}
_user.save(user)
_write_embed_draft(dst_key_prefix, user['storymaps'][dst_id])
if published_on:
_write_embed_published(dst_key_prefix, user['storymaps'][dst_id])
return jsonify(user['storymaps'][dst_id])
except Exception, e:
traceback.print_exc()
return jsonify({'error': str(e)})
示例2: storymap_migrate
def storymap_migrate(user):
"""
Migrate a storymap
@title = storymap title
@url = storymap base url
@draft_on = ...
@published_on = ...
@file_list = json encoded list of file names
"""
try:
title, src_url, draft_on, file_list_json = _request_get_required("title", "url", "draft_on", "file_list")
published_on = _request_get("published_on")
file_list = json.loads(file_list_json)
dst_id = _make_storymap_id(user, title)
dst_key_prefix = storage.key_prefix(user["uid"], dst_id)
dst_url = settings.AWS_STORAGE_BUCKET_URL + dst_key_prefix
dst_img_url = dst_url + "_images/"
re_img = re.compile(r".*\.(png|gif|jpg|jpeg)$", re.I)
re_src = re.compile(r"%s" % src_url)
for file_name in file_list:
file_url = "%s%s" % (src_url, file_name)
if file_name.endswith(".json"):
key_name = storage.key_name(user["uid"], dst_id, file_name)
r = requests.get(file_url)
storage.save_json(key_name, re_src.sub(dst_img_url, r.text))
elif re_img.match(file_name):
key_name = storage.key_name(user["uid"], dst_id, "_images", file_name)
storage.save_from_url(key_name, file_url)
else:
continue # skip
user["storymaps"][dst_id] = {"id": dst_id, "title": title, "draft_on": draft_on, "published_on": published_on}
_user.save(user)
_write_embed_draft(dst_key_prefix, user["storymaps"][dst_id])
if published_on:
_write_embed_published(dst_key_prefix, user["storymaps"][dst_id])
return jsonify(user["storymaps"][dst_id])
except Exception, e:
traceback.print_exc()
return jsonify({"error": str(e)})
示例3: storymap_get
def storymap_get(user, id):
"""Get storymap"""
try:
key_name = storage.key_name(user['uid'], id, 'draft.json')
data = storage.load_json(key_name)
return jsonify({'meta': user['storymaps'][id], 'data': data})
except storage.StorageException, e:
traceback.print_exc()
return jsonify({'error': str(e), 'error_detail': e.detail})
示例4: storymap_delete
def storymap_delete(user, id):
"""Delete storymap"""
try:
key_name = storage.key_name(user['uid'], id)
key_list, marker = storage.list_keys(key_name, 50)
for key in key_list:
storage.delete(key.name);
del user['storymaps'][id]
_user.save(user)
return jsonify({})
except Exception, e:
traceback.print_exc()
return jsonify({'error': str(e)})
示例5: storymap_save
def storymap_save(user, id):
"""Save draft storymap"""
try:
data = _request_get_required('d')
key_name = storage.key_name(user['uid'], id, 'draft.json')
content = json.loads(data)
storage.save_json(key_name, content)
user['storymaps'][id]['draft_on'] = _utc_now()
_user.save(user)
return jsonify({'meta': user['storymaps'][id]})
except storage.StorageException, e:
traceback.print_exc()
return jsonify({'error': str(e), 'error_detail': e.detail})
示例6: storymap_image_save
def storymap_image_save(user, id):
"""
Save storymap image
@id = storymap id
@name = file name
@content = data:URL representing the file's data as base64 encoded string
"""
try:
name, content = _request_get_required('name', 'content')
m = re.match('data:(.+);base64,(.+)', content)
if m:
content_type = m.group(1)
content = m.group(2).decode('base64')
else:
raise Exception('Expected content as data-url')
key_name = storage.key_name(user['uid'], id, '_images', name)
storage.save_from_data(key_name, content_type, content)
return jsonify({'url': settings.AWS_STORAGE_BUCKET_URL+key_name})
except storage.StorageException, e:
traceback.print_exc()
return jsonify({'error': str(e), 'error_detail': e.detail})
示例7: storymap_image_save
def storymap_image_save(user, id):
"""
Save storymap image
@id = storymap id
@name = file name
@content = data:URL representing the file's data as base64 encoded string
"""
try:
name, content = _request_get_required("name", "content")
m = re.match("data:(.+);base64,(.+)", content)
if m:
content_type = m.group(1)
content = m.group(2).decode("base64")
else:
raise Exception("Expected content as data-url")
key_name = storage.key_name(user["uid"], id, "_images", name)
storage.save_from_data(key_name, content_type, content)
return jsonify({"url": settings.AWS_STORAGE_BUCKET_URL + key_name})
except storage.StorageException, e:
traceback.print_exc()
return jsonify({"error": str(e), "error_detail": e.detail})