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

📄 statusprefs.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
📖 第 1 页 / 共 2 页
字号:
# -*- coding: ISO8859-1 -*-# $Id: StatusPrefs.py 3679 2006-10-13 12:43:20Z jodal $## Copyright 2003, 2004 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: Hans J鴕gen Hoel <hansjorg@orakel.ntnu.no>#"""Contains classes for the status preferences page"""################################################### Importsimport psycopg, cPickle, re, nav.dbimport StatusDefaultPrefsfrom StatusSections import *################################################### ConstantsBASEPATH = '/status/'ADMIN_USER_ID = '1'################################################### Classesclass HandleStatusPrefs:    """     This class displays the prefs page and handles     loading and saving of preferences     """    STATUS_PROPERTY = 'statusprefs'    sectionBoxTypes = []    editSectionBoxes = []    addBarTitle = None    addBarSelectOptions = []    addBarSelectName = None    addBarSubmitName = None    addBarSubmitTitle = None    addBarSaveName = None    addBarSaveTitle = None    actionBarUpName = None    actionBarDelName = None    radioButtonName = None    formAction = BASEPATH + 'prefs/status.py'    isAdmin = False    adminHeader = 'Save default prefs (admin only)'    adminHelp = 'Save this layout as a default for users without any ' + \                'saved status page preference.'    adminButton = 'Save as default'    def __init__(self,req):        self.editSectionBoxes = []        self.req = req        form = req.form                # Admin gets to select between all orgs and can save def prefs        if str(req.session['user'].id) == ADMIN_USER_ID:            self.isAdmin = True        self.orgList = req.session['user'].getOrgIds()        # Make a list of the available SectionBox types        sectionBoxTypeList = []        sectionBoxTypeList.append(NetboxSectionBox)        sectionBoxTypeList.append(NetboxMaintenanceSectionBox)        sectionBoxTypeList.append(ServiceSectionBox)        sectionBoxTypeList.append(ServiceMaintenanceSectionBox)        sectionBoxTypeList.append(ModuleSectionBox)	sectionBoxTypeList.append(ThresholdSectionBox)        # Make a dictionary of typeId,SectionBox        self.sectionBoxTypes = dict([(section.typeId,section) for \        section in sectionBoxTypeList])               # Create the add bar select options        self.addBarSelectOptions = []         for typeId,section in self.sectionBoxTypes.items():            self.addBarSelectOptions.append((typeId,section.name))        # Define the addbar and the action bar        self.addBarTitle = 'Select a section to add'        self.addBarSelectName = 'prefs_sel'        self.addBarSubmitTitle = 'Add'        self.addBarSubmitName = 'prefs_add'        self.addBarSaveName = 'prefs_save'        self.addBarSaveTitle = 'Save'        self.addBarSaveDefName = 'prefs_save_def'        self.addBarSaveDefTitle = 'Save default'        self.actionBarUpName = 'prefs_up'        self.actionBarDelName = 'prefs_del'        self.radioButtonName = 'prefs_radio'        # Parse the form and add the sections that are already present        # If this is the initial loading of the prefs page, nothing        # will be present, and the prefs will be loaded further down        for field in form.list:            if field:                control = re.match('([a-zA-Z]*)_([0-9]+)$',field.name)                if control:                    if len(control.groups()) == 2:                        controlType = control.group(1)                        controlNumber = control.group(2)                        controlBaseName = control.string                                                if self.sectionBoxTypes.has_key(controlType):                            # read settings from the form, and pass them on                            # to recreate the section box                            settings = []                            # field.value contains the title                            settings.append(field.value)                            # go through the form controls and add the                            # list of filter options to the settings                            selectDict = dict()                            for selectfield in form.list:                                #select = re.match('([a-zA-Z]*)_(' + \                                #controlNumber + ')_([a-zA-Z]+)',\                                #selectfield.name)                                                                select = re.match(controlType + '_(' + \                                controlNumber + ')_([a-zA-Z]+)',\                                selectfield.name)                                if select:                                    if len(select.groups()) == 2:                                        # regexp matches, this is a select                                        # control                                        control = select.string                                        if not selectDict.has_key(control):                                            selectDict[control] = []                                        value = selectfield.value                                        if not value:                                            # Nothing is selected                                            # equals "All" selected                                            value = FILTER_ALL_SELECTED                                        selectDict[control].append(value)                            # append filtersettings                            settings.append(selectDict)                            self.addSectionBox(controlType,settings,                                               controlBaseName)                # Handle all possible actions        if form.has_key(self.addBarSubmitName):            # Add button pressed            self.addSectionBox(req.form[self.addBarSelectName])        elif req.form.has_key(self.addBarSaveName):            # Save button pressed            self.savePrefs()        elif req.form.has_key(self.addBarSaveDefName):            # Save default pressed            self.saveDefaultPrefs()        elif (req.form.has_key(self.actionBarDelName) or \        req.form.has_key(self.actionBarUpName)):            # Handle action buttons (move up and delete)            if form.has_key(self.radioButtonName):                selected = form[self.radioButtonName]                if form.has_key(self.actionBarDelName):                    # delete selected                    index = 0                    for editSectionBox in self.editSectionBoxes:                        if editSectionBox.controlBaseName == selected:                            break                        index += 1                    del(self.editSectionBoxes[index])                                    elif form.has_key(self.actionBarUpName):                    # move up selected                    index = 0                    for editSectionBox in self.editSectionBoxes:                        if editSectionBox.controlBaseName == selected:                            break                        index += 1                    if index > 0:                        tempBox = self.editSectionBoxes[index]                        self.editSectionBoxes[index] = \                        self.editSectionBoxes[index-1]                                                self.editSectionBoxes[index-1] = tempBox        else:            # No buttons submitted, initial load of the prefs page.            # Get saved prefs from the database.            prefs = self.loadPrefs(req)            self.setPrefs(prefs)        return    def addSectionBox(self,addTypeId,settings=None,controlBaseName=None):        sectionType = self.sectionBoxTypes[addTypeId]        controlNumber = self.getNextControlNumber(addTypeId)        self.editSectionBoxes.append(EditSectionBox(sectionType,\        controlNumber,settings,controlBaseName,self.orgList))         return    def getNextControlNumber(self,typeId):        """        Get the next free control basename for section of type typeId         (for example if service_0_orgid exists, next free controlnumber is 1)        """        # make a list of the basenames already in use        baseNameList = []        for section in self.editSectionBoxes:            baseNameList.append(section.controlBaseName)        # find the next available control number, start at 0

⌨️ 快捷键说明

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