Changeset 2657 for pykota/trunk/pykota/storages/sql.py
- Timestamp:
- 02/09/06 00:15:46 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/sql.py
r2654 r2657 203 203 fields = result[0] 204 204 user.ident = fields.get("id") 205 user.Name = self.databaseToUserCharset(fields.get("username", username))206 205 user.LimitBy = fields.get("limitby") or "quota" 207 206 user.AccountBalance = fields.get("balance") 208 207 user.LifeTimePaid = fields.get("lifetimepaid") 209 208 user.Email = fields.get("email") 209 user.Description = self.databaseToUserCharset(fields.get("description")) 210 210 user.OverCharge = fields.get("overcharge", 1.0) 211 211 user.Exists = 1 … … 220 220 fields = result[0] 221 221 group.ident = fields.get("id") 222 group.Name = self.databaseToUserCharset(fields.get("groupname", groupname))223 222 group.LimitBy = fields.get("limitby") or "quota" 224 223 group.AccountBalance = fields.get("balance") 225 224 group.LifeTimePaid = fields.get("lifetimepaid") 225 group.Description = self.databaseToUserCharset(fields.get("description")) 226 226 group.Exists = 1 227 227 return group … … 235 235 fields = result[0] 236 236 printer.ident = fields.get("id") 237 printer.Name = self.databaseToUserCharset(fields.get("printername", printername))238 237 printer.PricePerJob = fields.get("priceperjob") or 0.0 239 238 printer.PricePerPage = fields.get("priceperpage") or 0.0 … … 255 254 fields = result[0] 256 255 code.ident = fields.get("id") 257 code.BillingCode = self.databaseToUserCharset(fields.get("billingcode"))258 256 code.Description = self.databaseToUserCharset(fields.get("description") or "") 259 257 code.Balance = fields.get("balance") or 0.0 … … 375 373 result = self.doSearch("SELECT * FROM printers") 376 374 if result : 375 patterns = printerpattern.split(",") 377 376 for record in result : 378 377 pname = self.databaseToUserCharset(record["printername"]) 379 if self.tool.matchString(pname, p rinterpattern.split(",")) :378 if self.tool.matchString(pname, patterns) : 380 379 printer = StoragePrinter(self, pname) 381 380 printer.ident = record.get("id") … … 394 393 return printers 395 394 395 def getMatchingUsers(self, userpattern) : 396 """Returns the list of all users for which name matches a certain pattern.""" 397 users = [] 398 # We 'could' do a SELECT username FROM users WHERE username LIKE ... 399 # but we don't because other storages semantics may be different, so every 400 # storage should use fnmatch to match patterns and be storage agnostic 401 result = self.doSearch("SELECT * FROM users") 402 if result : 403 patterns = userpattern.split(",") 404 for record in result : 405 uname = self.databaseToUserCharset(record["username"]) 406 if self.tool.matchString(uname, patterns) : 407 user = StorageUser(self, uname) 408 user.ident = record.get("id") 409 user.LimitBy = record.get("limitby") or "quota" 410 user.AccountBalance = record.get("balance") 411 user.LifeTimePaid = record.get("lifetimepaid") 412 user.Email = record.get("email") 413 user.Description = self.databaseToUserCharset(record.get("description")) 414 user.OverCharge = record.get("overcharge", 1.0) 415 user.Exists = 1 416 users.append(user) 417 self.cacheEntry("USERS", user.Name, user) 418 return users 419 420 def getMatchingGroups(self, grouppattern) : 421 """Returns the list of all groups for which name matches a certain pattern.""" 422 groups = [] 423 # We 'could' do a SELECT groupname FROM groups WHERE groupname LIKE ... 424 # but we don't because other storages semantics may be different, so every 425 # storage should use fnmatch to match patterns and be storage agnostic 426 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) GROUP BY groups.id,groups.groupname,groups.limitby,groups.description") 427 if result : 428 patterns = grouppattern.split(",") 429 for record in result : 430 gname = self.databaseToUserCharset(record["groupname"]) 431 if self.tool.matchString(gname, patterns) : 432 group = StorageGroup(self, gname) 433 group.ident = record.get("id") 434 group.LimitBy = record.get("limitby") or "quota" 435 group.AccountBalance = record.get("balance") 436 group.LifeTimePaid = record.get("lifetimepaid") 437 group.Description = self.databaseToUserCharset(record.get("description")) 438 group.Exists = 1 439 groups.append(group) 440 self.cacheEntry("GROUPS", group.Name, group) 441 return groups 442 396 443 def getMatchingBillingCodes(self, billingcodepattern) : 397 444 """Returns the list of all billing codes for which the label matches a certain pattern.""" … … 399 446 result = self.doSearch("SELECT * FROM billingcodes") 400 447 if result : 448 patterns = billingcodepattern.split(",") 401 449 for record in result : 402 450 bcode = self.databaseToUserCharset(record["billingcode"]) 403 if self.tool.matchString(bcode, billingcodepattern.split(",")) :451 if self.tool.matchString(bcode, patterns) : 404 452 code = StorageBillingCode(self, bcode) 405 453 code.ident = record.get("id")