Show
Ignore:
Timestamp:
01/13/08 01:22:35 (16 years ago)
Author:
jerome
Message:

Database backends now convert from and to unicode instead of UTF-8.
The data dumper now expects unicode datas from the database.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/sql.py

    r3275 r3291  
    3636        user.LifeTimePaid = record.get("lifetimepaid") 
    3737        user.Email = record.get("email") 
    38         user.Description = self.databaseToUserCharset(record.get("description")) 
     38        user.Description = self.databaseToUnicode(record.get("description")) 
    3939        user.OverCharge = record.get("overcharge", 1.0) 
    4040        user.Exists = True 
     
    4848        group.AccountBalance = record.get("balance") 
    4949        group.LifeTimePaid = record.get("lifetimepaid") 
    50         group.Description = self.databaseToUserCharset(record.get("description")) 
     50        group.Description = self.databaseToUnicode(record.get("description")) 
    5151        group.Exists = True 
    5252        return group 
     
    6464        else : 
    6565            printer.PassThrough = False 
    66         printer.Description = self.databaseToUserCharset(record.get("description") or "") # TODO : is 'or ""' still needed ? 
     66        printer.Description = self.databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ? 
    6767        printer.Exists = True 
    6868        return printer 
     
    7676        job.JobPrice = record.get("jobprice") 
    7777        job.JobAction = record.get("action") 
    78         job.JobFileName = self.databaseToUserCharset(record.get("filename") or "")  
    79         job.JobTitle = self.databaseToUserCharset(record.get("title") or "")  
     78        job.JobFileName = self.databaseToUnicode(record.get("filename") or "")  
     79        job.JobTitle = self.databaseToUnicode(record.get("title") or "")  
    8080        job.JobCopies = record.get("copies") 
    81         job.JobOptions = self.databaseToUserCharset(record.get("options") or "")  
     81        job.JobOptions = self.databaseToUnicode(record.get("options") or "")  
    8282        job.JobDate = record.get("jobdate") 
    8383        job.JobHostName = record.get("hostname") 
     
    8585        job.JobMD5Sum = record.get("md5sum") 
    8686        job.JobPages = record.get("pages") 
    87         job.JobBillingCode = self.databaseToUserCharset(record.get("billingcode") or "") 
     87        job.JobBillingCode = self.databaseToUnicode(record.get("billingcode") or "") 
    8888        job.PrecomputedJobSize = record.get("precomputedjobsize") 
    8989        job.PrecomputedJobPrice = record.get("precomputedjobprice") 
    90         job.UserName = self.databaseToUserCharset(record.get("username")) 
    91         job.PrinterName = self.databaseToUserCharset(record.get("printername")) 
     90        job.UserName = self.databaseToUnicode(record.get("username")) 
     91        job.PrinterName = self.databaseToUnicode(record.get("printername")) 
    9292        if job.JobTitle == job.JobFileName == job.JobOptions == "hidden" : 
    9393            (job.JobTitle, job.JobFileName, job.JobOptions) = (_("Hidden because of privacy concerns"),) * 3 
     
    138138        code = StorageBillingCode(self, billingcode) 
    139139        code.ident = record.get("id") 
    140         code.Description = self.databaseToUserCharset(record.get("description") or "") # TODO : is 'or ""' still needed ? 
     140        code.Description = self.databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ? 
    141141        code.Balance = record.get("balance") or 0.0 
    142142        code.PageCounter = record.get("pagecounter") or 0 
     
    149149            expressions = [] 
    150150            for (k, v) in only.items() : 
    151                 expressions.append("%s=%s" % (k, self.doQuote(self.userCharsetToDatabase(v)))) 
     151                expressions.append("%s=%s" % (k, self.doQuote(self.unicodeToDatabase(v)))) 
    152152            return " AND ".join(expressions)      
    153153        return ""         
     
    299299                self.tool.printInfo("Object %s has no %s attribute !" % (repr(record), attribute), "error") 
    300300            else : 
    301                 attrval = self.databaseToUserCharset(attrval) 
     301                attrval = self.databaseToUnicode(attrval) 
    302302                if patterns : 
    303303                    if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : 
     
    351351        """Extracts user information given its name.""" 
    352352        result = self.doSearch("SELECT * FROM users WHERE username=%s"\ 
    353                       % self.doQuote(self.userCharsetToDatabase(username))) 
     353                      % self.doQuote(self.unicodeToDatabase(username))) 
    354354        if result : 
    355355            return self.storageUserFromRecord(username, result[0]) 
     
    360360        """Extracts group information given its name.""" 
    361361        result = self.doSearch("SELECT groups.*,COALESCE(SUM(balance), 0.0) AS balance, COALESCE(SUM(lifetimepaid), 0.0) AS lifetimepaid FROM groups LEFT OUTER JOIN users ON users.id IN (SELECT userid FROM groupsmembers WHERE groupid=groups.id) WHERE groupname=%s GROUP BY groups.id,groups.groupname,groups.limitby,groups.description" \ 
    362                       % self.doQuote(self.userCharsetToDatabase(groupname))) 
     362                      % self.doQuote(self.unicodeToDatabase(groupname))) 
    363363        if result : 
    364364            return self.storageGroupFromRecord(groupname, result[0]) 
     
    369369        """Extracts printer information given its name.""" 
    370370        result = self.doSearch("SELECT * FROM printers WHERE printername=%s" \ 
    371                       % self.doQuote(self.userCharsetToDatabase(printername))) 
     371                      % self.doQuote(self.unicodeToDatabase(printername))) 
    372372        if result : 
    373373            return self.storagePrinterFromRecord(printername, result[0]) 
     
    378378        """Extracts a billing code information given its name.""" 
    379379        result = self.doSearch("SELECT * FROM billingcodes WHERE billingcode=%s" \ 
    380                       % self.doQuote(self.userCharsetToDatabase(label))) 
     380                      % self.doQuote(self.unicodeToDatabase(label))) 
    381381        if result : 
    382382            return self.storageBillingCodeFromRecord(label, result[0]) 
     
    416416        if result : 
    417417            for record in result : 
    418                 user = self.storageUserFromRecord(self.databaseToUserCharset(record.get("username")), \ 
     418                user = self.storageUserFromRecord(self.databaseToUnicode(record.get("username")), \ 
    419419                                                  record) 
    420420                groupmembers.append(user) 
     
    428428        if result : 
    429429            for record in result : 
    430                 groups.append(self.getGroup(self.databaseToUserCharset(record.get("groupname")))) 
     430                groups.append(self.getGroup(self.databaseToUnicode(record.get("groupname")))) 
    431431        return groups         
    432432         
     
    438438            for record in result : 
    439439                if record["groupid"] != printer.ident : # in case of integrity violation 
    440                     parentprinter = self.getPrinter(self.databaseToUserCharset(record.get("printername"))) 
     440                    parentprinter = self.getPrinter(self.databaseToUnicode(record.get("printername"))) 
    441441                    if parentprinter.Exists : 
    442442                        pgroups.append(parentprinter) 
     
    460460                    patdict[p] = None 
    461461            for record in result : 
    462                 pname = self.databaseToUserCharset(record["printername"]) 
     462                pname = self.databaseToUnicode(record["printername"]) 
    463463                if patdict.has_key(pname) or self.tool.matchString(pname, patterns) : 
    464464                    printer = self.storagePrinterFromRecord(pname, record) 
     
    484484                    patdict[p] = None 
    485485            for record in result : 
    486                 uname = self.databaseToUserCharset(record["username"]) 
     486                uname = self.databaseToUnicode(record["username"]) 
    487487                if patdict.has_key(uname) or self.tool.matchString(uname, patterns) : 
    488488                    user = self.storageUserFromRecord(uname, record) 
     
    508508                    patdict[p] = None 
    509509            for record in result : 
    510                 gname = self.databaseToUserCharset(record["groupname"]) 
     510                gname = self.databaseToUnicode(record["groupname"]) 
    511511                if patdict.has_key(gname) or self.tool.matchString(gname, patterns) : 
    512512                    group = self.storageGroupFromRecord(gname, record) 
     
    529529                    patdict[p] = None 
    530530            for record in result : 
    531                 codename = self.databaseToUserCharset(record["billingcode"]) 
     531                codename = self.databaseToUnicode(record["billingcode"]) 
    532532                if patdict.has_key(codename) or self.tool.matchString(codename, patterns) : 
    533533                    code = self.storageBillingCodeFromRecord(codename, record) 
     
    542542        if result : 
    543543            for record in result : 
    544                 uname = self.databaseToUserCharset(record.get("username")) 
     544                uname = self.databaseToUnicode(record.get("username")) 
    545545                if self.tool.matchString(uname, names) : 
    546546                    user = self.storageUserFromRecord(uname, record) 
     
    557557        if result : 
    558558            for record in result : 
    559                 gname = self.databaseToUserCharset(record.get("groupname")) 
     559                gname = self.databaseToUnicode(record.get("groupname")) 
    560560                if self.tool.matchString(gname, names) : 
    561561                    group = self.getGroup(gname) 
     
    570570            return oldentry 
    571571        self.doModify("INSERT INTO printers (printername, passthrough, maxjobsize, description, priceperpage, priceperjob) VALUES (%s, %s, %s, %s, %s, %s)" \ 
    572                           % (self.doQuote(self.userCharsetToDatabase(printer.Name)), \ 
     572                          % (self.doQuote(self.unicodeToDatabase(printer.Name)), \ 
    573573                             self.doQuote((printer.PassThrough and "t") or "f"), \ 
    574574                             self.doQuote(printer.MaxJobSize or 0), \ 
    575                              self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 
     575                             self.doQuote(self.unicodeToDatabase(printer.Description)), \ 
    576576                             self.doQuote(printer.PricePerPage or 0.0), \ 
    577577                             self.doQuote(printer.PricePerJob or 0.0))) 
     
    585585            return oldentry 
    586586        self.doModify("INSERT INTO billingcodes (billingcode, balance, pagecounter, description) VALUES (%s, %s, %s, %s)" \ 
    587                            % (self.doQuote(self.userCharsetToDatabase(bcode.BillingCode)),  
     587                           % (self.doQuote(self.unicodeToDatabase(bcode.BillingCode)),  
    588588                              self.doQuote(bcode.Balance or 0.0), \ 
    589589                              self.doQuote(bcode.PageCounter or 0), \ 
    590                               self.doQuote(self.userCharsetToDatabase(bcode.Description)))) 
     590                              self.doQuote(self.unicodeToDatabase(bcode.Description)))) 
    591591        bcode.isDirty = False 
    592592        return None # the entry created doesn't need further modification 
     
    598598            return oldentry 
    599599        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ 
    600                                      (self.doQuote(self.userCharsetToDatabase(user.Name)), \ 
     600                                     (self.doQuote(self.unicodeToDatabase(user.Name)), \ 
    601601                                      self.doQuote(user.LimitBy or 'quota'), \ 
    602602                                      self.doQuote(user.AccountBalance or 0.0), \ 
     
    604604                                      self.doQuote(user.Email), \ 
    605605                                      self.doQuote(user.OverCharge), \ 
    606                                       self.doQuote(self.userCharsetToDatabase(user.Description)))) 
     606                                      self.doQuote(self.unicodeToDatabase(user.Description)))) 
    607607        if user.PaymentsBacklog : 
    608608            for (value, comment) in user.PaymentsBacklog : 
     
    618618            return oldentry 
    619619        self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ 
    620                               (self.doQuote(self.userCharsetToDatabase(group.Name)), \ 
     620                              (self.doQuote(self.unicodeToDatabase(group.Name)), \ 
    621621                               self.doQuote(group.LimitBy or "quota"), \ 
    622                                self.doQuote(self.userCharsetToDatabase(group.Description)))) 
     622                               self.doQuote(self.unicodeToDatabase(group.Description)))) 
    623623        group.isDirty = False 
    624624        return None # the entry created doesn't need further modification 
     
    677677                              % (self.doQuote((printer.PassThrough and "t") or "f"), \ 
    678678                                 self.doQuote(printer.MaxJobSize or 0), \ 
    679                                  self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 
     679                                 self.doQuote(self.unicodeToDatabase(printer.Description)), \ 
    680680                                 self.doQuote(printer.PricePerPage or 0.0), \ 
    681681                                 self.doQuote(printer.PricePerJob or 0.0), \ 
     
    690690                                  self.doQuote(user.Email), \ 
    691691                                  self.doQuote(user.OverCharge), \ 
    692                                   self.doQuote(self.userCharsetToDatabase(user.Description)), \ 
     692                                  self.doQuote(self.unicodeToDatabase(user.Description)), \ 
    693693                                  self.doQuote(user.ident))) 
    694694                                   
     
    697697        self.doModify("UPDATE groups SET limitby=%s, description=%s WHERE id=%s" \ 
    698698                               % (self.doQuote(group.LimitBy or 'quota'), \ 
    699                                   self.doQuote(self.userCharsetToDatabase(group.Description)), \ 
     699                                  self.doQuote(self.unicodeToDatabase(group.Description)), \ 
    700700                                  self.doQuote(group.ident))) 
    701701         
     
    717717                            % (self.doQuote(bcode.Balance or 0.0), \ 
    718718                               self.doQuote(bcode.PageCounter or 0), \ 
    719                                self.doQuote(self.userCharsetToDatabase(bcode.Description)), \ 
     719                               self.doQuote(self.unicodeToDatabase(bcode.Description)), \ 
    720720                               self.doQuote(bcode.ident))) 
    721721        
     
    735735        """Adds a new payment to the payments history.""" 
    736736        if user.ident is not None : 
    737             self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 
     737            self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.unicodeToDatabase(comment)))) 
    738738        else :     
    739             self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote(self.userCharsetToDatabase(user.Name)), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 
     739            self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote(self.unicodeToDatabase(user.Name)), self.doQuote(amount), self.doQuote(self.unicodeToDatabase(comment)))) 
    740740         
    741741    def writeLastJobSize(self, lastjob, jobsize, jobprice) :         
     
    748748            # For legal reasons, we want to hide the title, filename and options 
    749749            title = filename = options = "hidden" 
    750         filename = self.userCharsetToDatabase(filename) 
    751         title = self.userCharsetToDatabase(title) 
    752         options = self.userCharsetToDatabase(options) 
    753         jobbilling = self.userCharsetToDatabase(jobbilling) 
     750        filename = self.unicodeToDatabase(filename) 
     751        title = self.unicodeToDatabase(title) 
     752        options = self.unicodeToDatabase(options) 
     753        jobbilling = self.unicodeToDatabase(jobbilling) 
    754754        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    755755            if jobsize is not None : 
     
    814814            where.append("hostname=%s" % self.doQuote(hostname)) 
    815815        if billingcode is not None :     
    816             where.append("billingcode=%s" % self.doQuote(self.userCharsetToDatabase(billingcode))) 
     816            where.append("billingcode=%s" % self.doQuote(self.unicodeToDatabase(billingcode))) 
    817817        if jobid is not None :     
    818             where.append("jobid=%s" % self.doQuote(jobid)) # TODO : jobid is text, so self.userCharsetToDatabase(jobid) but do all of them as well. 
     818            where.append("jobid=%s" % self.doQuote(jobid)) # TODO : jobid is text, so self.unicodeToDatabase(jobid) but do all of them as well. 
    819819        if start is not None :     
    820820            where.append("jobdate>=%s" % self.doQuote(start))