VirtualBox

Ignore:
Timestamp:
Dec 29, 2016 10:13:20 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
112520
Message:

testmanager/base.py: Started on basic filtering structures.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testmanager/core/base.py

    r62484 r65025  
    11531153
    11541154
     1155class FilterCriterionValueAndDescription(object):
     1156    """
     1157    A filter criterion value and its description.
     1158    """
     1159
     1160    def __init__(self, oValue, sDesc):
     1161        self.oValue = oValue;   ##< Typically the ID of something in the database.
     1162        self.sDesc  = sDesc;    ##< What to display.
     1163
     1164
     1165class FilterCriterion(object):
     1166    """
     1167    A filter criterion.
     1168    """
     1169
     1170    ## @name The state.
     1171    ## @{
     1172    ksState_NotSelected = 'not-selected';
     1173    ksState_Selected    = 'selected';
     1174    ## @}
     1175
     1176    ## @name The kind of filtering.
     1177    ## @{
     1178    ksKind_AnyOf = 'any-of';    ##< Any of the selected values are included (common).
     1179    ksKind_AllOf = 'all-of';    ##< All of the selected values must be matched (rare).
     1180    ## @}
     1181
     1182    ## @name The value type.
     1183    ## @{
     1184    ksType_UInt   = 'uint';     ##< unsigned integer value.
     1185    ksType_String = 'string';   ##< string value.
     1186    ## @}
     1187
     1188    def __init__(self, sName, sVarNm = None, sTypeNm = ksType_UInt, sState = ksState_NotSelected, sKind = ksKind_AnyOf):
     1189        self.sName      = sName;
     1190        self.sState     = sState;
     1191        self.sVarNm     = sVarNm if sVarNm is not None else sName;
     1192        self.sTypeNm    = sTypeNm;
     1193        self.sKind      = sKind;
     1194        self.aoSelected = []; # Single value, any type.
     1195        self.aoPossible = []; # type: list[FilterCriterionValueAndDescription]
     1196
     1197
     1198class ModelFilterBase(ModelBase):
     1199    """
     1200    Base class for filters.
     1201
     1202    Filters are used to narrow down data that is displayed in a list or
     1203    report.  It differs a little from ModelDataBase in that it's not tied to a
     1204    database table, but one or more database queries that are typically very
     1205    complicated.
     1206
     1207    The filter object has two roles:
     1208
     1209      1. It is used by a ModelLogicBase descendant to store the available
     1210         filtering options for data begin displayed.
     1211
     1212      2. It decodes and stores the filtering options submitted by the user so
     1213         a ModeLogicBase descendant can use it to construct WHERE statements.
     1214
     1215    The ModelFilterBase class is related to the ModelDataBase class in that it
     1216    decodes user parameters and stores data, however it is not a descendant.
     1217
     1218    Note! In order to reduce URL lengths, we use very very brief parameter
     1219          names for the filters.
     1220    """
     1221
     1222    def __init__(self):
     1223        ModelBase.__init__(self);
     1224        self.aCriteria = []; # type: list[FilterCriterion]
     1225
     1226    def initFromParams(self, oDisp): # type: (WuiDispatcherBase) -> self
     1227        """
     1228        Initialize the object from parameters.
     1229
     1230        Returns self. Raises exception on invalid parameter value.
     1231        """
     1232
     1233        for oCriterion in self.aCriteria:
     1234            if oCriterion.sType == FilterCriterion.ksType_UInt:
     1235                oCriterion.aoSelected = oDisp.getListOfIntParams(oCriterion.sVarNm, iMin = 0, aiDefaults = []);
     1236            else:
     1237                oCriterion.aoSelected = oDisp.getListOfStrParams(oCriterion.sVarNm, asDefaults = []);
     1238            if len(oCriterion.aoSelected):
     1239                oCriterion.sState = FilterCriterion.ksState_Selected;
     1240            else:
     1241                oCriterion.sState = FilterCriterion.ksState_NotSelected;
     1242        return self;
     1243
     1244
     1245
    11551246class ModelLogicBase(ModelBase): # pylint: disable=R0903
    11561247    """
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette