Changeset 3291 for pykota/trunk/pykota/storages/sql.py
- Timestamp:
- 01/13/08 01:22:35 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r3275 r3291 36 36 user.LifeTimePaid = record.get("lifetimepaid") 37 37 user.Email = record.get("email") 38 user.Description = self.databaseToU serCharset(record.get("description"))38 user.Description = self.databaseToUnicode(record.get("description")) 39 39 user.OverCharge = record.get("overcharge", 1.0) 40 40 user.Exists = True … … 48 48 group.AccountBalance = record.get("balance") 49 49 group.LifeTimePaid = record.get("lifetimepaid") 50 group.Description = self.databaseToU serCharset(record.get("description"))50 group.Description = self.databaseToUnicode(record.get("description")) 51 51 group.Exists = True 52 52 return group … … 64 64 else : 65 65 printer.PassThrough = False 66 printer.Description = self.databaseToU serCharset(record.get("description") or "") # TODO : is 'or ""' still needed ?66 printer.Description = self.databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ? 67 67 printer.Exists = True 68 68 return printer … … 76 76 job.JobPrice = record.get("jobprice") 77 77 job.JobAction = record.get("action") 78 job.JobFileName = self.databaseToU serCharset(record.get("filename") or "")79 job.JobTitle = self.databaseToU serCharset(record.get("title") or "")78 job.JobFileName = self.databaseToUnicode(record.get("filename") or "") 79 job.JobTitle = self.databaseToUnicode(record.get("title") or "") 80 80 job.JobCopies = record.get("copies") 81 job.JobOptions = self.databaseToU serCharset(record.get("options") or "")81 job.JobOptions = self.databaseToUnicode(record.get("options") or "") 82 82 job.JobDate = record.get("jobdate") 83 83 job.JobHostName = record.get("hostname") … … 85 85 job.JobMD5Sum = record.get("md5sum") 86 86 job.JobPages = record.get("pages") 87 job.JobBillingCode = self.databaseToU serCharset(record.get("billingcode") or "")87 job.JobBillingCode = self.databaseToUnicode(record.get("billingcode") or "") 88 88 job.PrecomputedJobSize = record.get("precomputedjobsize") 89 89 job.PrecomputedJobPrice = record.get("precomputedjobprice") 90 job.UserName = self.databaseToU serCharset(record.get("username"))91 job.PrinterName = self.databaseToU serCharset(record.get("printername"))90 job.UserName = self.databaseToUnicode(record.get("username")) 91 job.PrinterName = self.databaseToUnicode(record.get("printername")) 92 92 if job.JobTitle == job.JobFileName == job.JobOptions == "hidden" : 93 93 (job.JobTitle, job.JobFileName, job.JobOptions) = (_("Hidden because of privacy concerns"),) * 3 … … 138 138 code = StorageBillingCode(self, billingcode) 139 139 code.ident = record.get("id") 140 code.Description = self.databaseToU serCharset(record.get("description") or "") # TODO : is 'or ""' still needed ?140 code.Description = self.databaseToUnicode(record.get("description") or "") # TODO : is 'or ""' still needed ? 141 141 code.Balance = record.get("balance") or 0.0 142 142 code.PageCounter = record.get("pagecounter") or 0 … … 149 149 expressions = [] 150 150 for (k, v) in only.items() : 151 expressions.append("%s=%s" % (k, self.doQuote(self.u serCharsetToDatabase(v))))151 expressions.append("%s=%s" % (k, self.doQuote(self.unicodeToDatabase(v)))) 152 152 return " AND ".join(expressions) 153 153 return "" … … 299 299 self.tool.printInfo("Object %s has no %s attribute !" % (repr(record), attribute), "error") 300 300 else : 301 attrval = self.databaseToU serCharset(attrval)301 attrval = self.databaseToUnicode(attrval) 302 302 if patterns : 303 303 if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : … … 351 351 """Extracts user information given its name.""" 352 352 result = self.doSearch("SELECT * FROM users WHERE username=%s"\ 353 % self.doQuote(self.u serCharsetToDatabase(username)))353 % self.doQuote(self.unicodeToDatabase(username))) 354 354 if result : 355 355 return self.storageUserFromRecord(username, result[0]) … … 360 360 """Extracts group information given its name.""" 361 361 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.u serCharsetToDatabase(groupname)))362 % self.doQuote(self.unicodeToDatabase(groupname))) 363 363 if result : 364 364 return self.storageGroupFromRecord(groupname, result[0]) … … 369 369 """Extracts printer information given its name.""" 370 370 result = self.doSearch("SELECT * FROM printers WHERE printername=%s" \ 371 % self.doQuote(self.u serCharsetToDatabase(printername)))371 % self.doQuote(self.unicodeToDatabase(printername))) 372 372 if result : 373 373 return self.storagePrinterFromRecord(printername, result[0]) … … 378 378 """Extracts a billing code information given its name.""" 379 379 result = self.doSearch("SELECT * FROM billingcodes WHERE billingcode=%s" \ 380 % self.doQuote(self.u serCharsetToDatabase(label)))380 % self.doQuote(self.unicodeToDatabase(label))) 381 381 if result : 382 382 return self.storageBillingCodeFromRecord(label, result[0]) … … 416 416 if result : 417 417 for record in result : 418 user = self.storageUserFromRecord(self.databaseToU serCharset(record.get("username")), \418 user = self.storageUserFromRecord(self.databaseToUnicode(record.get("username")), \ 419 419 record) 420 420 groupmembers.append(user) … … 428 428 if result : 429 429 for record in result : 430 groups.append(self.getGroup(self.databaseToU serCharset(record.get("groupname"))))430 groups.append(self.getGroup(self.databaseToUnicode(record.get("groupname")))) 431 431 return groups 432 432 … … 438 438 for record in result : 439 439 if record["groupid"] != printer.ident : # in case of integrity violation 440 parentprinter = self.getPrinter(self.databaseToU serCharset(record.get("printername")))440 parentprinter = self.getPrinter(self.databaseToUnicode(record.get("printername"))) 441 441 if parentprinter.Exists : 442 442 pgroups.append(parentprinter) … … 460 460 patdict[p] = None 461 461 for record in result : 462 pname = self.databaseToU serCharset(record["printername"])462 pname = self.databaseToUnicode(record["printername"]) 463 463 if patdict.has_key(pname) or self.tool.matchString(pname, patterns) : 464 464 printer = self.storagePrinterFromRecord(pname, record) … … 484 484 patdict[p] = None 485 485 for record in result : 486 uname = self.databaseToU serCharset(record["username"])486 uname = self.databaseToUnicode(record["username"]) 487 487 if patdict.has_key(uname) or self.tool.matchString(uname, patterns) : 488 488 user = self.storageUserFromRecord(uname, record) … … 508 508 patdict[p] = None 509 509 for record in result : 510 gname = self.databaseToU serCharset(record["groupname"])510 gname = self.databaseToUnicode(record["groupname"]) 511 511 if patdict.has_key(gname) or self.tool.matchString(gname, patterns) : 512 512 group = self.storageGroupFromRecord(gname, record) … … 529 529 patdict[p] = None 530 530 for record in result : 531 codename = self.databaseToU serCharset(record["billingcode"])531 codename = self.databaseToUnicode(record["billingcode"]) 532 532 if patdict.has_key(codename) or self.tool.matchString(codename, patterns) : 533 533 code = self.storageBillingCodeFromRecord(codename, record) … … 542 542 if result : 543 543 for record in result : 544 uname = self.databaseToU serCharset(record.get("username"))544 uname = self.databaseToUnicode(record.get("username")) 545 545 if self.tool.matchString(uname, names) : 546 546 user = self.storageUserFromRecord(uname, record) … … 557 557 if result : 558 558 for record in result : 559 gname = self.databaseToU serCharset(record.get("groupname"))559 gname = self.databaseToUnicode(record.get("groupname")) 560 560 if self.tool.matchString(gname, names) : 561 561 group = self.getGroup(gname) … … 570 570 return oldentry 571 571 self.doModify("INSERT INTO printers (printername, passthrough, maxjobsize, description, priceperpage, priceperjob) VALUES (%s, %s, %s, %s, %s, %s)" \ 572 % (self.doQuote(self.u serCharsetToDatabase(printer.Name)), \572 % (self.doQuote(self.unicodeToDatabase(printer.Name)), \ 573 573 self.doQuote((printer.PassThrough and "t") or "f"), \ 574 574 self.doQuote(printer.MaxJobSize or 0), \ 575 self.doQuote(self.u serCharsetToDatabase(printer.Description)), \575 self.doQuote(self.unicodeToDatabase(printer.Description)), \ 576 576 self.doQuote(printer.PricePerPage or 0.0), \ 577 577 self.doQuote(printer.PricePerJob or 0.0))) … … 585 585 return oldentry 586 586 self.doModify("INSERT INTO billingcodes (billingcode, balance, pagecounter, description) VALUES (%s, %s, %s, %s)" \ 587 % (self.doQuote(self.u serCharsetToDatabase(bcode.BillingCode)),587 % (self.doQuote(self.unicodeToDatabase(bcode.BillingCode)), 588 588 self.doQuote(bcode.Balance or 0.0), \ 589 589 self.doQuote(bcode.PageCounter or 0), \ 590 self.doQuote(self.u serCharsetToDatabase(bcode.Description))))590 self.doQuote(self.unicodeToDatabase(bcode.Description)))) 591 591 bcode.isDirty = False 592 592 return None # the entry created doesn't need further modification … … 598 598 return oldentry 599 599 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge, description) VALUES (%s, %s, %s, %s, %s, %s, %s)" % \ 600 (self.doQuote(self.u serCharsetToDatabase(user.Name)), \600 (self.doQuote(self.unicodeToDatabase(user.Name)), \ 601 601 self.doQuote(user.LimitBy or 'quota'), \ 602 602 self.doQuote(user.AccountBalance or 0.0), \ … … 604 604 self.doQuote(user.Email), \ 605 605 self.doQuote(user.OverCharge), \ 606 self.doQuote(self.u serCharsetToDatabase(user.Description))))606 self.doQuote(self.unicodeToDatabase(user.Description)))) 607 607 if user.PaymentsBacklog : 608 608 for (value, comment) in user.PaymentsBacklog : … … 618 618 return oldentry 619 619 self.doModify("INSERT INTO groups (groupname, limitby, description) VALUES (%s, %s, %s)" % \ 620 (self.doQuote(self.u serCharsetToDatabase(group.Name)), \620 (self.doQuote(self.unicodeToDatabase(group.Name)), \ 621 621 self.doQuote(group.LimitBy or "quota"), \ 622 self.doQuote(self.u serCharsetToDatabase(group.Description))))622 self.doQuote(self.unicodeToDatabase(group.Description)))) 623 623 group.isDirty = False 624 624 return None # the entry created doesn't need further modification … … 677 677 % (self.doQuote((printer.PassThrough and "t") or "f"), \ 678 678 self.doQuote(printer.MaxJobSize or 0), \ 679 self.doQuote(self.u serCharsetToDatabase(printer.Description)), \679 self.doQuote(self.unicodeToDatabase(printer.Description)), \ 680 680 self.doQuote(printer.PricePerPage or 0.0), \ 681 681 self.doQuote(printer.PricePerJob or 0.0), \ … … 690 690 self.doQuote(user.Email), \ 691 691 self.doQuote(user.OverCharge), \ 692 self.doQuote(self.u serCharsetToDatabase(user.Description)), \692 self.doQuote(self.unicodeToDatabase(user.Description)), \ 693 693 self.doQuote(user.ident))) 694 694 … … 697 697 self.doModify("UPDATE groups SET limitby=%s, description=%s WHERE id=%s" \ 698 698 % (self.doQuote(group.LimitBy or 'quota'), \ 699 self.doQuote(self.u serCharsetToDatabase(group.Description)), \699 self.doQuote(self.unicodeToDatabase(group.Description)), \ 700 700 self.doQuote(group.ident))) 701 701 … … 717 717 % (self.doQuote(bcode.Balance or 0.0), \ 718 718 self.doQuote(bcode.PageCounter or 0), \ 719 self.doQuote(self.u serCharsetToDatabase(bcode.Description)), \719 self.doQuote(self.unicodeToDatabase(bcode.Description)), \ 720 720 self.doQuote(bcode.ident))) 721 721 … … 735 735 """Adds a new payment to the payments history.""" 736 736 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.u serCharsetToDatabase(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)))) 738 738 else : 739 self.doModify("INSERT INTO payments (userid, amount, description) VALUES ((SELECT id FROM users WHERE username=%s), %s, %s)" % (self.doQuote(self.u serCharsetToDatabase(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)))) 740 740 741 741 def writeLastJobSize(self, lastjob, jobsize, jobprice) : … … 748 748 # For legal reasons, we want to hide the title, filename and options 749 749 title = filename = options = "hidden" 750 filename = self.u serCharsetToDatabase(filename)751 title = self.u serCharsetToDatabase(title)752 options = self.u serCharsetToDatabase(options)753 jobbilling = self.u serCharsetToDatabase(jobbilling)750 filename = self.unicodeToDatabase(filename) 751 title = self.unicodeToDatabase(title) 752 options = self.unicodeToDatabase(options) 753 jobbilling = self.unicodeToDatabase(jobbilling) 754 754 if (not self.disablehistory) or (not printer.LastJob.Exists) : 755 755 if jobsize is not None : … … 814 814 where.append("hostname=%s" % self.doQuote(hostname)) 815 815 if billingcode is not None : 816 where.append("billingcode=%s" % self.doQuote(self.u serCharsetToDatabase(billingcode)))816 where.append("billingcode=%s" % self.doQuote(self.unicodeToDatabase(billingcode))) 817 817 if jobid is not None : 818 where.append("jobid=%s" % self.doQuote(jobid)) # TODO : jobid is text, so self.u serCharsetToDatabase(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. 819 819 if start is not None : 820 820 where.append("jobdate>=%s" % self.doQuote(start))