本文整理汇总了Python中resource.Resource.get方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.get方法的具体用法?Python Resource.get怎么用?Python Resource.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource.Resource
的用法示例。
在下文中一共展示了Resource.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
def __init__(self, request):
"""Box"""
resource_provider = ResourceProvider()
resource = Resource(resource_provider)
self.charts = []
self.chart_type = None
self.layout = Layout(request)
self.body = ''
self.javascript = ''
self.chart_name = request.matchdict['box_name']
chart_format = os.path.splitext(request.environ['PATH_INFO'])[1]
# Go through the registry, and find the resource for this box
# XXX This should be a dictionary
for res in RESOURCES_REGISTRY:
if res[0] == self.chart_name:
self.resources = [res]
if chart_format == '.html':
self.render_html(request)
elif chart_format == '.csv':
self.body = resource.get(self.chart_name, CSV, request.matchdict)
elif chart_format == '.json':
self.body = resource.get(self.chart_name, JSON, request.matchdict)
else:
print "Format not supported %s" % chart_format
raise AttributeError
示例2: get_user_resource_tags
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
def get_user_resource_tags(username, collectionid, resourceid):
rsrc = Resource()
rsrc.create()
result = rsrc.get(username, collectionid, resourceid)
if not result:
return [{'No tags'}]
else:
return [{'TagText': result[0]['tags']}]
示例3: ResourceTest
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
class ResourceTest(object):
def __init__(self):
self.photostore_resource = Resource(True)
self.photostore_resource.create()
def test_resource(self):
curtime = str(time.time())
self.photostore_resource.put('gopa', 1, '[%s]: test put' % curtime,
curtime)
data = self.photostore_resource.get('gopa', 1, curtime)
for d in data:
print 'GET: data cltnid %s, uid %s, description %s\n' % \
(d['g_rsrc_collectionid'], d['g_uid'], \
d['description'])
data = self.photostore_resource.get('gopa', 1, None)
for d in data:
print 'QUERY: data cltnid %s, uid %s, description %s\n' % \
(d['g_rsrc_collectionid'], d['g_uid'], d['description'])
示例4: get_user_resource_details
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
def get_user_resource_details(username, collectionid, resourceid):
rsrc = Resource()
rsrc.create()
result = rsrc.get(username, collectionid, resourceid)
if not result:
return {'Not found'}
else:
return {
'FileSource': result[0]['hires_url'],
'Description' : 'Powered by PhotoStore Technology',
'Location': 'Palo Alto'
}
示例5: get_resource
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
def get_resource(data):
if not data:
return {'NOTFOUND'}
rsrc = Resource(True)
if 'collectionid' in data:
collectionid = data['collectionid']
else:
collectionid = None
if 'resourceid' in data:
resourceid = data['resourceid']
else:
resourceid = None
return rsrc.get(data['user'], collectionid, resourceid)
示例6: Restyler
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
class Restyler(object):
"""Gets resources and renders them as charts"""
def __init__(self, request, cells):
resource_provider = ResourceProvider()
self.resource = Resource(resource_provider)
self.cells = cells
self.resources = self.get_resources()
self.charts = self.get_charts(request)
self.packages = self.get_packages()
self.javascript = render_javascript(self.charts, self.packages)
def get_charts(self, request):
"""Return the charts needed for rendering"""
url = get_absolute_url(request)
charts = []
for chart in self.get_chart_infos(request):
chart['chartoptions_rendered'] = ""
# Render the chart to JSon
if not JSON in chart or chart[JSON] is None:
pass
elif not 'charttype' in chart:
pass
else:
chart['data'] = chart[JSON]
chart['chartoptions']['is3D'] = False
rendered = render_chartoptions(chart['chartoptions'])
chart['chartoptions_rendered'] = rendered
chart['csv_download_url'] = url + "%s.csv" % chart['id']
chart['html_download_url'] = url + "%s.html" % chart['id']
chart['module_id'] = self.get_module_id(chart)
if self.cells.get_new_row_for_chart(chart['id']):
chart['module_style'] = "clear: both;"
else:
chart['module_style'] = ""
rendered = render_description(request,
chart.get('description', ''),
chart.get('description_type', ''))
chart['description_rendered'] = rendered
# Use an id with the postfox '_div' to make collisions unprobable
chart['div_id'] = chart['id'] + '_div'
charts.append(chart)
return charts
def get_module_id(self, chart):
"""Return the HTML id attribute value for the chart."""
return self.cells.get_column_for_chart(chart['id'])
def get_packages(self):
"""Google Chart tools has a lot of packages covered in the corecharts
already, and the only chart type that necessitates loading a package
is the table.
"""
packages = set(['corechart'])
for chart in self.charts:
if chart.get('charttype', None) in ['Table', 'ImageSparkLine']:
packages.add(chart['charttype'].lower())
return packages
def get_resources(self):
"""Get a list of all resources"""
resources = []
# And keep track of any that were not found
unknown = set(self.cells.get_cells())
# Go through the registry, and take only the resources that are
# referenced from the cells of the layout
for resource in RESOURCES_REGISTRY:
if resource[0] in self.cells.get_cells():
if resource[0] in unknown:
# This is a known resource, so remove it from the unknown
unknown.remove(resource[0])
# Avoid duplicates
if not resource in resources:
resources.append(resource[:])
if len(unknown) > 0:
print "Unknown resources: %s" % unknown
raise AttributeError
return resources
def get_chart_infos(self, request):
"""Get all augmented charts from the resources in the context."""
charts = []
for name, method, content_types in self.resources:
# Fill an empty chart with the statistics resources based on the
# wanted content types
chart = BOXES[name].copy()
if not 'id' in chart:
# At least put in a default id
chart['id'] = name
success = True
for ctype in content_types:
result = self.resource.get(name, ctype, request.matchdict)
if result is None:
success = False
else:
chart[ctype] = result
if success:
# Call the method on the current context
method(self, chart)
charts.append(chart)
#.........这里部分代码省略.........
示例7: get_user_resources
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
def get_user_resources(username, collectionid, resourceid):
rsrc = Resource()
rsrc.create()
return rsrc.get(username, collectionid, resourceid)
示例8: get_user_resource_comments
# 需要导入模块: from resource import Resource [as 别名]
# 或者: from resource.Resource import get [as 别名]
def get_user_resource_comments(username, collectionid, resourceid):
rsrc = Resource()
rsrc.create()
result = rsrc.get(username, collectionid, resourceid)
return [{'CommentText': 'Nice pic!!'}]