當前位置: 首頁>>代碼示例>>Python>>正文


Python s3codec.S3Codec類代碼示例

本文整理匯總了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
開發者ID:AnithaT,項目名稱:eden,代碼行數:19,代碼來源:s3export.py

示例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
開發者ID:flavour,項目名稱:lacity,代碼行數:21,代碼來源:s3export.py

示例3: xls

    def xls(self, *args, **kwargs):

        codec = S3Codec.get_codec("xls").encode
        return codec(*args, **kwargs)
開發者ID:AyudaEcuador,項目名稱:eden,代碼行數:4,代碼來源:s3export.py

示例4: svg

    def svg(self, *args, **kwargs):

        codec = S3Codec.get_codec("svg").encode
        return codec(*args, **kwargs)
開發者ID:AyudaEcuador,項目名稱:eden,代碼行數:4,代碼來源:s3export.py

示例5: shp

    def shp(self, *args, **kwargs):

        codec = S3Codec.get_codec("shp").encode
        return codec(*args, **kwargs)
開發者ID:AyudaEcuador,項目名稱:eden,代碼行數:4,代碼來源:s3export.py

示例6: pdf

    def pdf(self, *args, **kwargs):

        codec = S3Codec.get_codec("pdf").encode
        return codec(*args, **kwargs)
開發者ID:AyudaEcuador,項目名稱:eden,代碼行數:4,代碼來源:s3export.py

示例7: pdfcard

    def pdfcard(self, *args, **kwargs):

        codec = S3Codec.get_codec("card")
        return codec.encode(*args, **kwargs)
開發者ID:ramdesh,項目名稱:eden,代碼行數:4,代碼來源:s3export.py

示例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
開發者ID:ahaym,項目名稱:eden,代碼行數:101,代碼來源:s3hierarchy.py


注:本文中的s3codec.S3Codec類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。