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