本文整理汇总了Python中s3codec.S3Codec类的典型用法代码示例。如果您正苦于以下问题:Python S3Codec类的具体用法?Python S3Codec怎么用?Python S3Codec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了S3Codec类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
"""
Constructor
@param manager: the S3ResourceController
@todo 2.3: error message completion
"""
T = current.T
self.ERROR = Storage(
REPORTLAB_ERROR = T("%(module)s not installed") % dict(module="ReportLab"),
NO_RECORDS = T("No records in this resource"),
XLWT_ERROR = T("%(module)s not installed") % dict(module="xlwt"),
)
self.xls = S3Codec.get_codec("xls").encode
self.pdf = S3Codec.get_codec("pdf").encode
示例2: __init__
def __init__(self, manager):
"""
Constructor
@param manager: the S3ResourceController
@todo 2.3: error message completion
"""
self.manager = manager
T = current.T
self.s3 = self.manager.s3
self.ERROR = Storage(
REPORTLAB_ERROR = T("ReportLab not installed"),
GERALDO_ERROR = T("Geraldo not installed"),
NO_RECORDS = T("No records in this resource"),
XLWT_ERROR = T("Xlwt not installed"),
)
self.xls = S3Codec.get_codec("xls").encode
示例3: xls
def xls(self, *args, **kwargs):
codec = S3Codec.get_codec("xls").encode
return codec(*args, **kwargs)
示例4: svg
def svg(self, *args, **kwargs):
codec = S3Codec.get_codec("svg").encode
return codec(*args, **kwargs)
示例5: shp
def shp(self, *args, **kwargs):
codec = S3Codec.get_codec("shp").encode
return codec(*args, **kwargs)
示例6: pdf
def pdf(self, *args, **kwargs):
codec = S3Codec.get_codec("pdf").encode
return codec(*args, **kwargs)
示例7: pdfcard
def pdfcard(self, *args, **kwargs):
codec = S3Codec.get_codec("card")
return codec.encode(*args, **kwargs)
示例8: export_xls
#.........这里部分代码省略.........
# Intepret the hierarchy_export setting for the resource
setting = resource.get_config("hierarchy_export", {})
field = setting.get("field")
if not field:
field = "name" if "name" in resource.fields else resource._id.name
prefix = setting.get("prefix", "Sub")
root = setting.get("root")
if not root:
root = "".join(s.capitalize() for s in resource.name.split("_"))
branch = setting.get("branch")
if not branch:
branch = "%s%s" % (prefix, root)
rfield = resource.resolve_selector(field)
# Get the list fields
list_fields = resource.list_fields("export_fields", id_column=False)
rfields = resource.resolve_selectors(list_fields, extra_fields=False)[0]
# Selectors = the fields to extract
selectors = [h.pkey.name, rfield.selector]
# Columns = the keys for the XLS Codec to access the rows
# Types = the data types of the columns (in same order!)
columns = []
types = []
# Generate the headers and type list for XLS Codec
headers = {}
for rf in rfields:
selectors.append(rf.selector)
if rf.colname == rfield.colname:
continue
columns.append(rf.colname)
headers[rf.colname] = rf.label
if rf.ftype == "virtual":
types.append("string")
else:
types.append(rf.ftype)
# Get the root nodes
if self.record_id:
if r.component and h.pkey.name != resource._id.name:
query = resource.table._id == self.record_id
row = current.db(query).select(h.pkey, limitby=(0, 1)).first()
if not row:
r.error(404, current.ERROR.BAD_RECORD)
roots = set([row[h.pkey]])
else:
roots = set([self.record_id])
else:
roots = h.roots
# Find all child nodes
all_nodes = h.findall(roots, inclusive=True)
# ...and extract their data from a clone of the resource
from s3query import FS
query = FS(h.pkey.name).belongs(all_nodes)
clone = current.s3db.resource(resource, filter=query)
data = clone.select(selectors, represent=True, raw_data=True)
# Convert into dict {hierarchy key: row}
hkey = str(h.pkey)
data_dict = dict((row._row[hkey], row) for row in data.rows)
# Add hierarchy headers and types
depth = max(h.depth(node_id) for node_id in roots)
htypes = []
hcolumns = []
colprefix = "HIERARCHY"
htype = "string" if rfield.ftype == "virtual" else rfield.ftype
for level in xrange(depth + 1):
col = "%s.%s" % (colprefix, level)
if level == 0:
headers[col] = root
elif level == 1:
headers[col] = branch
else:
headers[col] = "%s%s" % ("".join([prefix] * (level - 1)), branch)
hcolumns.append(col)
htypes.append(htype)
# Generate the output for XLS Codec
output = [headers, htypes + types]
for node_id in roots:
rows = h.export_node(
node_id, prefix=colprefix, depth=depth, hcol=rfield.colname, columns=columns, data=data_dict
)
output.extend(rows)
# Encode in XLS format
from s3codec import S3Codec
codec = S3Codec.get_codec("xls")
result = codec.encode(output, title=resource.name, list_fields=hcolumns + columns)
# Reponse headers and file name are set in codec
return result