Changeset 5135

Show
Ignore:
Timestamp:
03/17/09 11:51:49 (3 years ago)
Author:
pedro.gato
Message:

This makes dBizobj.filter() VirtualField? aware, they are handled after the real fields, creating a fake filter.
Also modify datanav SelectPage? to work with VirtualFields?, no changes to user code needed, VirtualFields? are now treated as any other ordinary field

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/biz/dBizobj.py

    r5099 r5135  
    3737        # now the DefaultValues property (used to be self.defaultValues attribute) 
    3838        self._defaultValues = {} 
     39 
     40        # PKId's of rows to be filtered out when 
     41        # filtering Virtual fields 
     42        self.__filterPKVirtual = [] 
    3943 
    4044        self._beforeInit() 
     
    995999            contains: expr in fld 
    9961000        """ 
    997         currPK = self.getPK() 
    998         self._CurrentCursor.filter(fld=fld, expr=expr, op=op) 
    999         newPK = self.getPK() 
    1000         if newPK != currPK: 
    1001             try: 
    1002                 self.moveToPK(currPK) 
    1003             except dabo.dException.RowNotFoundException: 
     1001        #currPK = self.getPK() 
     1002        if self.VirtualFields.has_key(fld): 
     1003            self.scan(self.scanVirtualFields, fld=fld, expr=expr, op=op, reverse=True) 
     1004            self._CurrentCursor.filterByExpression("%s IN (%s)" % (self.KeyField, ", ".join( "%i" % key for key in self.__filterPKVirtual))) 
     1005 
     1006            # clear filter id's 
     1007            self.__filterPKVirtual = [] 
     1008        else: 
     1009            self._CurrentCursor.filter(fld=fld, expr=expr, op=op) 
     1010 
     1011        #try: 
     1012        #   newPK = self.getPK() 
     1013        #except dException.NoRecordsException: 
     1014        #   newPK = currPK 
     1015 
     1016        #if newPK != currPK: 
     1017        #   try: 
     1018        #       self.moveToPK(currPK) 
     1019        #   except dabo.dException.RowNotFoundException: 
    10041020                # The old row was filtered out of the dataset 
    1005                 self.first() 
    1006  
     1021        #       self.first() 
     1022 
     1023    def scanVirtualFields(self, fld, expr, op): 
     1024        virtValue = self.getFieldVal(fld) 
     1025 
     1026        if op.lower() in ("eq", "equals", "="): 
     1027            if virtValue == expr: 
     1028                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1029 
     1030        elif op.lower() in ("ne", "nequals", "!="): 
     1031            if virtValue != expr: 
     1032                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1033 
     1034        elif op.lower() in ("gt", ">", "greater than"): 
     1035            if expr > virtValue: 
     1036                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1037 
     1038        elif op.lower() in ("gte", ">=", "greater than/equal to"): 
     1039            if expr >= virtValue: 
     1040                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1041 
     1042        elif op.lower() in ("lt", "<", "less than"): 
     1043            if expr < virtValue: 
     1044                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1045 
     1046        elif op.lower() in ("lte", "<=", "less than/equal to"): 
     1047            if expr <= virtValue: 
     1048                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1049 
     1050        elif op.lower() in ("starts with", "begins with"): 
     1051            if virtValue.startswith(expr): 
     1052                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1053 
     1054        elif op.lower() in ("endswith"): 
     1055            if virtValue.endswith(expr): 
     1056                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
     1057 
     1058        elif op.lower() in ("contains"): 
     1059            if expr in virtValue: 
     1060                self.__filterPKVirtual.append(self.getFieldVal(self.KeyField)) 
    10071061 
    10081062    def removeFilter(self): 
  • trunk/dabo/db/dCursorMixin.py

    r5015 r5135  
    11811181        self._records = self._records.filter(fld=fld, expr=expr, op=op) 
    11821182 
     1183    def filterByExpression(self, expr): 
     1184        """Allows you to filter by any expression that would make a 
     1185        valid 'where' clause in SQLite. 
     1186        """ 
     1187        self._records = self._records.filterByExpression(expr) 
    11831188 
    11841189    def removeFilter(self): 
  • trunk/dabo/db/dDataSet.py

    r5000 r5135  
    211211        valid 'where' clause in SQLite. 
    212212        """ 
     213        if not self: 
     214            # No rows, so nothing to filter 
     215            return self 
     216 
    213217        stmnt = "select * from dataset where %s" % (expr) 
    214218        ret = self.execute(stmnt) 
  • trunk/dabo/lib/datanav/Page.py

    r4954 r5135  
    131131        self.selectFields = {} 
    132132        self.sortFields = {} 
     133        self.__virtualFilters = [] 
    133134        self.sortIndex = 0 
    134135     
     
    243244        whr = "" 
    244245        for fld in flds: 
     246            if biz.VirtualFields.has_key(fld): 
     247                #virtual field, save for later use and ignore 
     248                self.__virtualFilters.append(fld) 
     249                continue 
    245250            if fld == "limit": 
    246251                # Handled elsewhere 
     
    367372            ret = frm.requery(_fromSelectPage=True) 
    368373 
     374        if bizobj.RowCount > 0: # don't bother applying this if there are no records to work on 
     375            # filter virtual fields 
     376            for vField in self.__virtualFilters: 
     377                opVal = self.selectFields[vField]["op"].Value 
     378                ctrl = self.selectFields[vField]["ctrl"] 
     379 
     380                if not _(IGNORE_STRING) in opVal: 
     381                    bizobj.filter(vField, ctrl.Value, opVal.lower()) 
     382 
    369383        if ret: 
    370384            if self.Parent.SelectedPageNumber == 0: