Changeset 2654

Show
Ignore:
Timestamp:
02/08/06 13:48:53 (19 years ago)
Author:
jerome
Message:

Now non-ascii characters are accepted as part of usernames, groupnames or printernames.
Contrarily to with LDAP, this works fine with relationnal databases.

Files:
1 modified

Legend:

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

    r2653 r2654  
    198198        """Extracts user information given its name.""" 
    199199        user = StorageUser(self, username) 
     200        username = self.userCharsetToDatabase(username) 
    200201        result = self.doSearch("SELECT * FROM users WHERE username=%s LIMIT 1" % self.doQuote(username)) 
    201202        if result : 
    202203            fields = result[0] 
    203204            user.ident = fields.get("id") 
    204             user.Name = fields.get("username", username) 
     205            user.Name = self.databaseToUserCharset(fields.get("username", username)) 
    205206            user.LimitBy = fields.get("limitby") or "quota" 
    206207            user.AccountBalance = fields.get("balance") 
     
    214215        """Extracts group information given its name.""" 
    215216        group = StorageGroup(self, groupname) 
     217        groupname = self.userCharsetToDatabase(groupname) 
    216218        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 LIMIT 1" % self.doQuote(groupname)) 
    217219        if result : 
    218220            fields = result[0] 
    219221            group.ident = fields.get("id") 
    220             group.Name = fields.get("groupname", groupname) 
     222            group.Name = self.databaseToUserCharset(fields.get("groupname", groupname)) 
    221223            group.LimitBy = fields.get("limitby") or "quota" 
    222224            group.AccountBalance = fields.get("balance") 
     
    228230        """Extracts printer information given its name.""" 
    229231        printer = StoragePrinter(self, printername) 
     232        printername = self.userCharsetToDatabase(printername) 
    230233        result = self.doSearch("SELECT * FROM printers WHERE printername=%s LIMIT 1" % self.doQuote(printername)) 
    231234        if result : 
    232235            fields = result[0] 
    233236            printer.ident = fields.get("id") 
    234             printer.Name = fields.get("printername", printername) 
     237            printer.Name = self.databaseToUserCharset(fields.get("printername", printername)) 
    235238            printer.PricePerJob = fields.get("priceperjob") or 0.0 
    236239            printer.PricePerPage = fields.get("priceperpage") or 0.0 
     
    303306            lastjob.ident = fields.get("id") 
    304307            lastjob.JobId = fields.get("jobid") 
    305             lastjob.UserName = fields.get("username") 
     308            lastjob.UserName = self.databaseToUserCharset(fields.get("username")) 
    306309            lastjob.PrinterPageCounter = fields.get("pagecounter") 
    307310            lastjob.JobSize = fields.get("jobsize") 
     
    331334        if result : 
    332335            for record in result : 
    333                 user = StorageUser(self, record.get("username")) 
     336                user = StorageUser(self, self.databaseToUserCharset(record.get("username"))) 
    334337                user.ident = record.get("userid") 
    335338                user.LimitBy = record.get("limitby") or "quota" 
     
    349352        if result : 
    350353            for record in result : 
    351                 groups.append(self.getGroup(record.get("groupname"))) 
     354                groups.append(self.getGroup(self.databaseToUserCharset(record.get("groupname")))) 
    352355        return groups         
    353356         
     
    359362            for record in result : 
    360363                if record["groupid"] != printer.ident : # in case of integrity violation 
    361                     parentprinter = self.getPrinter(record.get("printername")) 
     364                    parentprinter = self.getPrinter(self.databaseToUserCharset(record.get("printername"))) 
    362365                    if parentprinter.Exists : 
    363366                        pgroups.append(parentprinter) 
     
    373376        if result : 
    374377            for record in result : 
    375                 if self.tool.matchString(record["printername"], printerpattern.split(",")) : 
    376                     printer = StoragePrinter(self, record["printername"]) 
     378                pname = self.databaseToUserCharset(record["printername"]) 
     379                if self.tool.matchString(pname, printerpattern.split(",")) : 
     380                    printer = StoragePrinter(self, pname) 
    377381                    printer.ident = record.get("id") 
    378382                    printer.PricePerJob = record.get("priceperjob") or 0.0 
     
    414418        if result : 
    415419            for record in result : 
    416                 if self.tool.matchString(record.get("username"), names) : 
    417                     user = StorageUser(self, record.get("username")) 
     420                uname = self.databaseToUserCharset(record.get("username")) 
     421                if self.tool.matchString(uname, names) : 
     422                    user = StorageUser(self, uname) 
    418423                    user.ident = record.get("uid") 
    419424                    user.LimitBy = record.get("limitby") or "quota" 
     
    443448        if result : 
    444449            for record in result : 
    445                 if self.tool.matchString(record.get("groupname"), names) : 
    446                     group = self.getGroup(record.get("groupname")) 
     450                gname = self.databaseToUserCharset(record.get("groupname")) 
     451                if self.tool.matchString(gname, names) : 
     452                    group = self.getGroup(gname) 
    447453                    grouppquota = self.getGroupPQuota(group, printer) 
    448454                    groupsandquotas.append((group, grouppquota)) 
     
    451457    def addPrinter(self, printername) :         
    452458        """Adds a printer to the quota storage, returns it.""" 
    453         self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(printername)) 
     459        self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(self.userCharsetToDatabase(printername))) 
    454460        return self.getPrinter(printername) 
    455461         
     
    461467    def addUser(self, user) :         
    462468        """Adds a user to the quota storage, returns it.""" 
    463         self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 
     469        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % \ 
     470                                         (self.doQuote(self.userCharsetToDatabase(user.Name)), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 
    464471        return self.getUser(user.Name) 
    465472         
    466473    def addGroup(self, group) :         
    467474        """Adds a group to the quota storage, returns it.""" 
    468         self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy or "quota"))) 
     475        self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % \ 
     476                                          (self.doQuote(self.userCharsetToDatabase(group.Name)), self.doQuote(group.LimitBy or "quota"))) 
    469477        return self.getGroup(group.Name) 
    470478 
     
    559567    def writeNewPayment(self, user, amount, comment="") : 
    560568        """Adds a new payment to the payments history.""" 
    561         self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(comment))) 
     569        self.doModify("INSERT INTO payments (userid, amount, description) VALUES (%s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(amount), self.doQuote(self.userCharsetToDatabase(comment)))) 
    562570         
    563571    def writeLastJobSize(self, lastjob, jobsize, jobprice) :         
     
    657665                job.PrecomputedJobSize = fields.get("precomputedjobsize") 
    658666                job.PrecomputedJobPrice = fields.get("precomputedjobprice") 
    659                 job.UserName = fields.get("username") 
    660                 job.PrinterName = fields.get("printername") 
     667                job.UserName = self.databaseToUserCharset(fields.get("username")) 
     668                job.PrinterName = self.databaseToUserCharset(fields.get("printername")) 
    661669                if job.JobTitle == job.JobFileName == job.JobOptions == "hidden" : 
    662670                    (job.JobTitle, job.JobFileName, job.JobOptions) = (_("Hidden because of privacy concerns"),) * 3