当前位置: 首页>>代码示例>>Python>>正文


Python FlagFramework.smart_unicode方法代码示例

本文整理汇总了Python中pyflag.FlagFramework.smart_unicode方法的典型用法代码示例。如果您正苦于以下问题:Python FlagFramework.smart_unicode方法的具体用法?Python FlagFramework.smart_unicode怎么用?Python FlagFramework.smart_unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyflag.FlagFramework的用法示例。


在下文中一共展示了FlagFramework.smart_unicode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_table

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import smart_unicode [as 别名]
    def render_table(self, query, result):
        """ Renders the actual table itself """
        result.result+='''<table class="PyFlagTable" >
        <thead><tr>'''

        ## Get a generator for the rows:
        g = self.generate_rows(query)
        
        ## Make the table headers with suitable order by links:
        hiddens = [ int(x) for x in query.getarray(self.hidden) ]

        self.column_names = []
        for e in range(len(self.elements)):
            if e in hiddens: continue
            new_query = query.clone()
            ui = result.__class__(result)
            n = self.elements[e].column_decorator(self.table, self.sql, query, ui)
            n = n or ui
            self.column_names.append(n)
            
            if self.order==e:
                if query.get('direction','1')=='1':
                    tmp = result.__class__(result)
                    new_query.set('order', e)
                    new_query.set('direction',0)
                    tmp.link("%s<img src='images/increment.png'>" % n, target= new_query, pane='pane')
                    result.result+="<th>%s</th>" % tmp
                else:
                    tmp = result.__class__(result)
                    new_query.set('order', e)
                    new_query.set('direction',1)
                    tmp.link("%s<img src='images/decrement.png'>" % n, target= new_query, pane='pane')
                    result.result+="<th>%s</th>" % tmp
            else:
                tmp = result.__class__(result)
                new_query.set('order', e)
                new_query.set('direction',1)
                tmp.link(n, target= new_query, pane='pane')
                result.result+="<th>%s</th>" % tmp

        result.result+='''</tr></thead><tbody class="scrollContent">'''

        old_sorted = None
        old_sorted_style = ''

        ## Total number of rows
        self.row_count=0

        for row in g:
            row_elements = []
            tds = ''

            ## Render each row at a time:
            for i in range(len(self.elements)):
                if i in hiddens: continue

                ## Give the row to the column element to allow it
                ## to translate the output suitably:
                value = row[self.elements[i].name]
                try:
                    cell_ui = result.__class__(result)
                    ## Elements are expected to render on cell_ui
                    tmp = self.elements[i].display(value,row,cell_ui)
                    if tmp: cell_ui = tmp
                except Exception, e:
                    pyflaglog.log(pyflaglog.ERROR, expand("Unable to render %r: %s" , (value , e)))

                ## Render the row styles so that equal values on
                ## the sorted column have the same style
                if i==self.order and value!=old_sorted:
                    old_sorted=value
                    if old_sorted_style=='':
                        old_sorted_style='alternateRow'
                    else:
                        old_sorted_style=''

                ## Render the sorted column with a different style
                if i==self.order:
                    tds+="<td class='sorted-column'>%s</td>" % (FlagFramework.smart_unicode(cell_ui))
                else:
                    tds+=DB.expand("<td class='table-cell'>%s</td>",cell_ui)

            result.result+="<tr class='%s'> %s </tr>\n" % (old_sorted_style,tds)
            self.row_count += 1
开发者ID:backupManager,项目名称:pyflag,代码行数:86,代码来源:UI.py


注:本文中的pyflag.FlagFramework.smart_unicode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。