Changeset 2768 for pykota/trunk/pykota
- Timestamp:
- 03/01/06 10:47:49 (18 years ago)
- Location:
- pykota/trunk/pykota/storages
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r2765 r2768 887 887 return groupsandquotas 888 888 889 def addPrinter(self, printername) : 890 """Adds a printer to the quota storage, returns it.""" 891 printername = self.userCharsetToDatabase(printername) 889 def addPrinter(self, printer) : 890 """Adds a printer to the quota storage, returns the old value if it already exists.""" 891 oldentry = self.getPrinter(printer.Name) 892 if oldentry.Exists : 893 return oldentry # we return the existing entry 894 printername = self.userCharsetToDatabase(printer.Name) 892 895 fields = { self.info["printerrdn"] : printername, 893 896 "objectClass" : ["pykotaObject", "pykotaPrinter"], 894 897 "cn" : printername, 895 898 "pykotaPrinterName" : printername, 896 "pykotaPricePerPage" : "0.0", 897 "pykotaPricePerJob" : "0.0", 898 "pykotaMaxJobSize" : "0", 899 "pykotaPassThrough" : "0", 899 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 900 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 901 "description" : self.userCharsetToDatabase(printer.Description or ""), 902 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 903 "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), 900 904 } 901 905 dn = "%s=%s,%s" % (self.info["printerrdn"], printername, self.info["printerbase"]) 902 906 self.doAdd(dn, fields) 903 return self.getPrinter(printername) 907 printer.isDirty = False 908 return None # the entry created doesn't need further modification 904 909 905 910 def addUser(self, user) : … … 1094 1099 fields = { 1095 1100 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 1096 "pykotaMaxJobSize" : (printer.MaxJobSize and str(printer.MaxJobSize)) or "0",1101 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0), 1097 1102 "description" : self.userCharsetToDatabase(printer.Description or ""), 1098 "pykotaPricePerPage" : str(printer.PricePerPage ),1099 "pykotaPricePerJob" : str(printer.PricePerJob ),1103 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), 1104 "pykotaPricePerJob" : str(printer.PricePerJob or 0.0), 1100 1105 } 1101 1106 self.doModify(printer.ident, fields) -
pykota/trunk/pykota/storages/sql.py
r2765 r2768 527 527 return groupsandquotas 528 528 529 def addPrinter(self, printername) : 530 """Adds a printer to the quota storage, returns it.""" 531 self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(self.userCharsetToDatabase(printername))) 532 return self.getPrinter(printername) 529 def addPrinter(self, printer) : 530 """Adds a printer to the quota storage, returns the old value if it already exists.""" 531 try : 532 self.doModify("INSERT INTO printers (printername, passthrough, maxjobsize, description, priceperpage, priceperjob) VALUES (%s, %s, %s, %s, %s, %s)" \ 533 % (self.doQuote(self.userCharsetToDatabase(printer.Name)), \ 534 self.doQuote((printer.PassThrough and "t") or "f"), \ 535 self.doQuote(printer.MaxJobSize or 0), \ 536 self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 537 self.doQuote(printer.PricePerPage or 0.0), \ 538 self.doQuote(printer.PricePerJob or 0.0))) 539 except PyKotaStorageError : 540 # TODO : check if this is an error different from a duplicate insert 541 # return the existing entry which has to be modified 542 return self.getPrinter(printer.Name) 543 else : 544 printer.isDirty = False 545 return None # the entry created doesn't need further modification 533 546 534 547 def addBillingCode(self, bcode) : … … 626 639 self.doModify("UPDATE printers SET passthrough=%s, maxjobsize=%s, description=%s, priceperpage=%s, priceperjob=%s WHERE id=%s" \ 627 640 % (self.doQuote((printer.PassThrough and "t") or "f"), \ 628 self.doQuote(printer.MaxJobSize ), \641 self.doQuote(printer.MaxJobSize or 0), \ 629 642 self.doQuote(self.userCharsetToDatabase(printer.Description)), \ 630 self.doQuote(printer.PricePerPage ), \631 self.doQuote(printer.PricePerJob ), \643 self.doQuote(printer.PricePerPage or 0.0), \ 644 self.doQuote(printer.PricePerJob or 0.0), \ 632 645 self.doQuote(printer.ident))) 633 646 … … 852 865 printerids = ", ".join(["%s" % self.doQuote(p.ident) for p in printers]) 853 866 self.deleteInTransaction([ 854 "DELETE FROM printergroupsmembers WHERE groupid IN (%s) OR printerid IN (%s)" % printerids,867 "DELETE FROM printergroupsmembers WHERE groupid IN (%s) OR printerid IN (%s)" % (printerids, printerids), 855 868 "DELETE FROM jobhistory WHERE printerid IN (%s)" % printerids, 856 869 "DELETE FROM grouppquota WHERE printerid IN (%s)" % printerids,