164 | | # get last values from Quota Storage |
165 | | (lastpagecounter, lastjobid, lastusername) = (pgc["pagecounter"], pgc["lastjobid"], pgc["lastusername"]) |
166 | | |
167 | | # if printer is off then we assume the correct counter value is the last one |
168 | | if printerIsOff : |
169 | | counterbeforejob = lastpagecounter |
| 168 | userid = kotafilter.storage.getUserId(username) |
| 169 | if userid is None : |
| 170 | # The user is unknown from the Quota Storage perspective |
| 171 | # we let the job pass through, but log a warning message |
| 172 | kotafilter.logger.log_message(_("User %s not registered in the PyKota system") % username, "warn") |
| 173 | else : |
| 174 | pgc = kotafilter.storage.getPrinterPageCounter(printerid) |
| 175 | if pgc is None : |
| 176 | # The printer hasn't been used yet, from PyKota's point of view |
| 177 | lasthistoryid = None |
| 178 | lastjobid = jobid |
| 179 | lastuserid = userid |
| 180 | lastusername = username |
| 181 | lastpagecounter = counterbeforejob |
| 182 | else : |
| 183 | # get last values from Quota Storage |
| 184 | (lasthistoryid, lastjobid, lastuserid, lastusername, lastpagecounter) = (pgc["id"], pgc["jobid"], pgc["userid"], pgc["username"], pgc["pagecounter"]) |
| 185 | |
| 186 | # if printer is off then we assume the correct counter value is the last one |
| 187 | if printerIsOff : |
| 188 | counterbeforejob = lastpagecounter |
| 189 | |
| 190 | # Update the quota for the previous user on this printer according |
| 191 | # to the job size (difference between actual counter and latest one from storage) |
| 192 | jobsize = (counterbeforejob - lastpagecounter) |
| 193 | if jobsize >= 0 : |
| 194 | kotafilter.storage.updateUserPQuota(lastuserid, printerid, jobsize) |
| 195 | kotafilter.storage.updateJobSizeInHistory(lasthistoryid, jobsize) |
| 196 | kotafilter.warnUserPQuota(lastusername) |
| 197 | else : |
| 198 | kotafilter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, lastusername, kotafilter.printername), "error") |
| 199 | |
| 200 | # Is the current user allowed to print at all ? |
| 201 | action = kotafilter.warnUserPQuota(username) |
171 | | # Update the last page counter and last username in the Quota Storage backend |
172 | | # set them to current user and |
173 | | kotafilter.storage.updatePrinterPageCounter(kotafilter.printername, username, counterbeforejob, jobid) |
174 | | |
175 | | # Was the printer ever used ? |
176 | | if (lastpagecounter is None) or (lastusername is None) : |
177 | | lastusername = username |
178 | | lastpagecounter = counterbeforejob |
| 203 | # adds the current job to history |
| 204 | kotafilter.storage.addJobToHistory(jobid, kotafilter.storage.getUserId(username), printerid, counterbeforejob, action) |
180 | | # Update the quota for the previous user on this printer according |
181 | | # to the job size (difference between actual counter and latest one from storage) |
182 | | jobsize = (counterbeforejob - lastpagecounter) |
183 | | if jobsize >= 0 : |
184 | | kotafilter.storage.updateUserPQuota(lastusername, kotafilter.printername, jobsize) |
185 | | kotafilter.warnUserPQuota(lastusername) |
186 | | else : |
187 | | kotafilter.logger.log_message(_("Error in page count value %i for user %s on printer %s") % (jobsize, kotafilter.printername, lastusername), "error") |
188 | | |
189 | | # Is the current user allowed to print at all ? |
190 | | # if no then die, else proceed. |
191 | | action = kotafilter.warnUserPQuota(username) |
192 | | if action == "DENY" : |
193 | | # No, just die cleanly |
194 | | return 1 |
| 206 | # if not allowed to print then die, else proceed. |
| 207 | if action == "DENY" : |
| 208 | # No, just die cleanly |
| 209 | return 1 |