# -*- coding: utf-8 -*- # $Id: wuibase.py 65051 2017-01-02 11:55:03Z vboxsync $ """ Test Manager Web-UI - Base Classes. """ __copyright__ = \ """ Copyright (C) 2012-2016 Oracle Corporation This file is part of VirtualBox Open Source Edition (OSE), as available from http://www.virtualbox.org. This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation, in version 2 as it comes in the "COPYING" file of the VirtualBox OSE distribution. VirtualBox OSE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. The contents of this file may alternatively be used under the terms of the Common Development and Distribution License Version 1.0 (CDDL) only, as it comes in the "COPYING.CDDL" file of the VirtualBox OSE distribution, in which case the provisions of the CDDL are applicable instead of those of the GPL. You may elect to license modified versions of this file under the terms and conditions of either the GPL or the CDDL or both. """ __version__ = "$Revision: 65051 $" # Standard python imports. import os; import sys; import string; # Validation Kit imports. from common import webutils, utils; from testmanager import config; from testmanager.core.base import ModelDataBase, ModelLogicBase, TMExceptionBase; from testmanager.core.db import TMDatabaseConnection; from testmanager.core.systemlog import SystemLogLogic, SystemLogData; from testmanager.core.useraccount import UserAccountLogic class WuiException(TMExceptionBase): """ For exceptions raised by Web UI code. """ pass; class WuiDispatcherBase(object): """ Base class for the Web User Interface (WUI) dispatchers. The dispatcher class defines the basics of the page (like base template, menu items, action). It is also responsible for parsing requests and dispatching them to action (POST) or/and content generators (GET+POST). The content returned by the generator is merged into the template and sent back to the webserver glue. """ ## @todo possible that this should all go into presentation. ## The action parameter. ksParamAction = 'Action'; ## The name of the default action. ksActionDefault = 'default'; ## The name of the current page number parameter used when displaying lists. ksParamPageNo = 'PageNo'; ## The name of the page length (list items) parameter when displaying lists. ksParamItemsPerPage = 'ItemsPerPage'; ## The name of the effective date (timestamp) parameter. ksParamEffectiveDate = 'EffectiveDate'; ## The name of the redirect-to (test manager relative url) parameter. ksParamRedirectTo = 'RedirectTo'; ## The name of the list-action parameter (WuiListContentWithActionBase). ksParamListAction = 'ListAction'; ## The name of the change log enabled/disabled parameter. ksParamChangeLogEnabled = 'ChangeLogEnabled'; ## The name of the parmaeter indicating the change log page number. ksParamChangeLogPageNo = 'ChangeLogPageNo'; ## The name of the parameter indicate number of change log entries per page. ksParamChangeLogEntriesPerPage = 'ChangeLogEntriesPerPage'; ## @name Dispatcher debugging parameters. ## {@ ksParamDbgSqlTrace = 'DbgSqlTrace'; ksParamDbgSqlExplain = 'DbgSqlExplain'; ## List of all debugging parameters. kasDbgParams = (ksParamDbgSqlTrace, ksParamDbgSqlExplain,); ## @} ## Special action return code for skipping _generatePage. Useful for # download pages and the like that messes with the HTTP header and more. ksDispatchRcAllDone = 'Done - Page has been rendered already'; def __init__(self, oSrvGlue, sScriptName): self._oSrvGlue = oSrvGlue; self._oDb = TMDatabaseConnection(self.dprint if config.g_kfWebUiSqlDebug else None, oSrvGlue = oSrvGlue); self._tsNow = None; # Set by getEffectiveDateParam. self._asCheckedParams = []; self._dParams = None; # Set by dispatchRequest. self._sAction = None; # Set by dispatchRequest. self._dDispatch = { self.ksActionDefault: self._actionDefault, }; # Template bits. self._sTemplate = 'template-default.html'; self._sPageTitle = '$$TODO$$'; # The page title. self._aaoMenus = []; # List of [sName, sLink, [ [sSideName, sLink], .. ] tuples. self._sPageFilter = ''; # The filter controls (optional). self._sPageBody = '$$TODO$$'; # The body text. self._dSideMenuFormAttrs = {}; # key/value with attributes for the side menu