Changeset 3142

Show
Ignore:
Timestamp:
02/08/07 21:13:03 (18 years ago)
Author:
jerome
Message:

Make start= and end= filters also work with payments. For an unknown
reason it didn't already work (not implemented !)...
Ensures that these filters are only allowed for payments and
history, otherwise an SQL syntax error could have occured.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r3141 r3142  
    2424    - 1.26alpha3 (2007-01-31) : 
    2525     
     26        - Ensures start= and end= filters are only allowed for history and  
     27          payments. Made start= or end= filters also work with payments. 
     28           
    2629        - Doesn't print banners anymore when the user cancelled the print job. 
    2730         
  • pykota/trunk/pykota/dumper.py

    r3133 r3142  
    108108            raise PyKotaToolError, _("XML output is disabled because the jaxml module is not available.") 
    109109             
    110         if options["sum"] and datatype not in ("payments", "history") :  
    111             raise PyKotaCommandLineError, _("Invalid data type [%s] for --sum command line option, see help.") % datatype 
    112              
     110        if datatype not in ("payments", "history") :  
     111            if options["sum"] :  
     112                raise PyKotaCommandLineError, _("Invalid data type [%s] for --sum command line option, see help.") % datatype 
     113            if extractonly.has_key("start") or extractonly.has_key("end") :     
     114                self.printInfo(_("Invalid filter for the %(datatype)s data type.") % locals(), "warn") 
     115                try : 
     116                    del extractonly["start"] 
     117                except KeyError :     
     118                    pass 
     119                try : 
     120                    del extractonly["end"] 
     121                except KeyError :     
     122                    pass 
    113123             
    114124        retcode = 0 
  • pykota/trunk/pykota/storages/ldapstorage.py

    r3133 r3142  
    16201620    def extractPayments(self, extractonly={}) : 
    16211621        """Extracts all payment records.""" 
     1622        startdate = extractonly.get("start") 
     1623        enddate = extractonly.get("end") 
     1624        (startdate, enddate) = self.cleanDates(startdate, enddate) 
    16221625        uname = extractonly.get("username") 
    16231626        entries = [u for u in [self.getUser(name) for name in self.getAllUsersNames(uname)] if u.Exists] 
     
    16261629            for entry in entries : 
    16271630                for (date, amount, description) in entry.Payments : 
    1628                     result.append((entry.Name, amount, date, description)) 
     1631                    if ((startdate is None) and (enddate is None)) or \ 
     1632                       ((startdate is None) and (date <= enddate)) or \ 
     1633                       ((enddate is None) and (date >= startdate)) or \ 
     1634                       ((date >= startdate) and (date <= enddate)) : 
     1635                        result.append((entry.Name, amount, date, description)) 
    16291636            return result         
    16301637         
  • pykota/trunk/pykota/storages/sql.py

    r3139 r3142  
    187187    def extractPayments(self, extractonly={}) : 
    188188        """Extracts all payment records.""" 
     189        startdate = extractonly.get("start") 
     190        enddate = extractonly.get("end") 
     191        for limit in ("start", "end") : 
     192            try : 
     193                del extractonly[limit] 
     194            except KeyError :     
     195                pass 
    189196        thefilter = self.createFilter(extractonly) 
    190197        if thefilter : 
    191198            thefilter = "AND %s" % thefilter 
     199        (startdate, enddate) = self.cleanDates(startdate, enddate) 
     200        if startdate :  
     201            thefilter = "%s AND date>=%s" % (thefilter, self.doQuote(startdate)) 
     202        if enddate :  
     203            thefilter = "%s AND date<=%s" % (thefilter, self.doQuote(enddate)) 
    192204        result = self.doRawSearch("SELECT username,payments.* FROM users,payments WHERE users.id=payments.userid %s ORDER BY payments.id ASC" % thefilter) 
    193205        return self.prepareRawResult(result)