⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 report.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
字号:
# -*- coding: ISO8859-1 -*-# $Id: Report.py 3836 2007-01-29 14:33:20Z mortenv $## Copyright 2003-2005 Norwegian University of Science and Technology## This file is part of Network Administration Visualized (NAV)## NAV is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## NAV is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with NAV; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA### Authors: Sigurd Gartmann <sigurd-nav@brogar.org>#import refrom nav.web.URI import URIclass Field:    def __init__(self):        self.title = ""        self.raw = ""    def __repr__(self):        return "<Field %s = %s>" % (self.title, self.raw)class Report:    """    A nice formatted Report object, ready for presentation    """            def __init__(self,configuration,database,path):        """        The constructor of the Report class        - configuration : a ReportConfig object containing all the configuration        - database      : a DatabaseResult object that will be modified according        to the configuration        - path          : the address of the requested page        """        self.formatted = database.result        self.rowcount = database.rowcount        self.sums = database.sums        self.limit = self.setLimit(configuration.limit)        self.offset = self.setOffset(configuration.offset)        self.address = self.stripPath(path)         self.header = configuration.header        self.hide = configuration.hidden        self.extra = configuration.extra        self.name = configuration.name        self.explain = configuration.explain        self.uri = configuration.uri                self.fields = configuration.sql_select + self.extra        self.sql_fields = configuration.sql_select_orig        self.fieldNum,self.fieldName = self.fieldNum(self.fields)        self.fieldsSum = len(self.fields)        self.shown = self.hideIndex()        self.uri = self.remakeURI(self.uri)        self.table = self.makeTableContents()        footers = self.makeTableFooters(self.sums)        self.table.setFooters(footers)        headers = self.makeTableHeaders(self.name,self.uri,self.explain,configuration.orderBy)        self.table.setHeaders(headers)        self.navigator = Navigator()        self.navigator.setNavigator(self.limit,self.offset,self.address,self.rowcount)        self.form = self.makeForm(self.name)        if database.error:            self.navigator.setMessage(database.error)    def setLimit(self,config):        """        returns the limit according to the configuration or the default (1000)        - config : the limit of the configuration        returns the limit of the configuration or 1000        """                if config:                        return config                else:            return 1000    def setOffset(self,config):        """        returns the offset according to the configuration or the default (0)        - config : the offset according th the configuration        returns the offset of the configuration or 0        """                if config:                        return config                else:            return 0    def stripPath(self,path):        """        removes the 'limit' and 'offset' arguments from the uri that will used on the page        - path : the path that will get its 'limit' and 'offset'- fields removed        returns the new path        """        uri = URI(path)        stripFields = ['limit','offset']        for field in stripFields:            if field in uri.args:                del uri.args[field]        return uri.make()    def fieldNum(self,fields):        """        returns a hash associating the field names to the field numbers        - fields : a list containing the field names        returns the hash with fieldname=>fieldnumber pairs        """                fieldNum = {}        fieldName = {}        for field in fields:            number = fields.index(field)            fieldNum[field] = number            fieldName[number] = field        return fieldNum,fieldName        def remakeURI(self,uri):        """        takes a hash of uris associated to their names, and returns a hash of uris associated to their field numbers. this is a more effective approach than doing queries to a dictionary.        - uri : a hash of fieldnames and their uris        returns a hash of fieldnumbers and their uris        """                uri_hash = uri        uri_new = {}        for key,value in uri_hash.items():            if self.fields.count(key):                key_index = self.fields.index(key)                if self.shown.count(key_index):                    uri_new[key_index] = value        return uri_new    def makeTableHeaders(self,name,uri,explain,sortList=[]):        """        makes the table headers        - name    : a hash containing the numbers and names of the fields        - uri     : a hash containing the numbers of the fields and their uris        - explain : a hash containing the numbers of the fields and the fields explicit explanations        returns a list of cells that later will represent the headers of the table        """                name_hash = name        explain_hash = explain        #bruker ikke uri enn

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -