125 | | result = self.doSearch("(&(objectClass=pykotaUserPQuota)(uid=*))", ["uid"], base=printerid) |
126 | | if result : |
127 | | return [(pquotauserid, fields["uid"][0]) for (pquotauserid, fields) in result] |
128 | | else : |
129 | | return |
| 121 | # first get the printer's name from the id |
| 122 | result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) |
| 123 | if result : |
| 124 | printername = result[0][1]["pykotaPrinterName"][0] |
| 125 | result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaUserName"]) |
| 126 | if result : |
| 127 | return [(pquotauserid, fields["pykotaUserName"][0]) for (pquotauserid, fields) in result] |
133 | | result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(cn=*))", ["cn"], base=printerid) |
134 | | if result : |
135 | | return [(pquotagroupid, fields["cn"][0]) for (pquotagroupid, fields) in result] |
136 | | else : |
137 | | return |
| 131 | # first get the printer's name from the id |
| 132 | result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) |
| 133 | if result : |
| 134 | printername = result[0][1]["pykotaPrinterName"][0] |
| 135 | result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaGroupName"]) |
| 136 | if result : |
| 137 | return [(pquotagroupid, fields["pykotaGroupName"][0]) for (pquotagroupid, fields) in result] |
175 | | def getUserBalance(self, userid) : |
176 | | """Returns the current account balance for a given user.""" |
177 | | shortuid = userid.split(",")[0] |
178 | | result = self.doSearch("(&(objectClass=pykotaUser)(%s))" % shortuid, ["pykotaBalance", "pykotaLifeTimePaid"]) |
179 | | if result : |
180 | | fields = result[0][1] |
181 | | return (float(fields["pykotaBalance"][0]), float(fields["pykotaLifeTimePaid"][0])) |
182 | | else : |
183 | | return |
184 | | |
185 | | def getGroupBalance(self, groupid) : |
| 173 | def getUserBalance(self, userquotaid) : |
| 174 | """Returns the current account balance for a given user quota identifier.""" |
| 175 | # first get the user's name from the user quota id |
| 176 | result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName"], base=userquotaid, scope=ldap.SCOPE_BASE) |
| 177 | if result : |
| 178 | username = result[0][1]["pykotaUserName"][0] |
| 179 | result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % username, ["pykotaBalance", "pykotaLifeTimePaid"]) |
| 180 | if result : |
| 181 | fields = result[0][1] |
| 182 | return (float(fields["pykotaBalance"][0]), float(fields["pykotaLifeTimePaid"][0])) |
| 183 | |
| 184 | def getUserBalanceFromUserId(self, userid) : |
| 185 | """Returns the current account balance for a given user id.""" |
| 186 | # first get the user's name from the user id |
| 187 | result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName"], base=userid, scope=ldap.SCOPE_BASE) |
| 188 | if result : |
| 189 | username = result[0][1]["pykotaUserName"][0] |
| 190 | result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % username, ["pykotaBalance", "pykotaLifeTimePaid"]) |
| 191 | if result : |
| 192 | fields = result[0][1] |
| 193 | return (float(fields["pykotaBalance"][0]), float(fields["pykotaLifeTimePaid"][0])) |
| 194 | |
| 195 | def getGroupBalance(self, groupquotaid) : |
187 | | groupname = groupid.split(",")[0].split("=")[1] |
188 | | members = self.getGroupMembersNames(groupname) |
189 | | balance = lifetimepaid = 0.0 |
190 | | for member in members : |
191 | | userid = self.getUserId(member) |
192 | | if userid : |
193 | | userbal = self.getUserBalance(userid) |
194 | | if userbal : |
195 | | (bal, paid) = userbal |
196 | | balance += bal |
197 | | lifetimepaid += paid |
198 | | return (balance, lifetimepaid) |
| 197 | # first get the group's name from the group quota id |
| 198 | result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName"], base=groupquotaid, scope=ldap.SCOPE_BASE) |
| 199 | if result : |
| 200 | groupname = result[0][1]["pykotaGroupName"][0] |
| 201 | members = self.getGroupMembersNames(groupname) |
| 202 | balance = lifetimepaid = 0.0 |
| 203 | for member in members : |
| 204 | userid = self.getUserId(member) |
| 205 | if userid : |
| 206 | userbal = self.getUserBalanceFromUserId(userid) |
| 207 | if userbal : |
| 208 | (bal, paid) = userbal |
| 209 | balance += bal |
| 210 | lifetimepaid += paid |
| 211 | return (balance, lifetimepaid) |
211 | | shortgid = groupid.split(",")[0] |
212 | | result = self.doSearch("(&(objectClass=pykotaGroup)(%s))" % shortgid, ["pykotaLimitBy"]) |
213 | | if result : |
214 | | return result[0][1]["pykotaLimitBy"][0] |
215 | | else : |
216 | | return |
| 221 | # first get the group's name from the group quota id |
| 222 | result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName"], base=groupquotaid, scope=ldap.SCOPE_BASE) |
| 223 | if result : |
| 224 | groupname = result[0][1]["pykotaGroupName"][0] |
| 225 | result = self.doSearch("(&(objectClass=pykotaGroup)(pykotaGroupName=%s))" % groupname, ["pykotaLimitBy"]) |
| 226 | if result : |
| 227 | return result[0][1]["pykotaLimitBy"][0] |
250 | | def getUserPQuota(self, userid, printerid) : |
251 | | """Returns the Print Quota information for a given (userid, printerid).""" |
252 | | result = self.doSearch("(&(objectClass=pykotaUserPQuota)(uid=*))", ["uid", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=userid) |
| 261 | def getUserPQuota(self, userquotaid, printerid) : |
| 262 | """Returns the Print Quota information for a given (userquotaid, printerid).""" |
| 263 | # first get the user's name from the id |
| 264 | result = self.doSearch("objectClass=pykotaUserPQuota", ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=userquotaid, scope=ldap.SCOPE_BASE) |
264 | | else : |
265 | | return |
266 | | |
267 | | def getGroupPQuota(self, groupid, printerid) : |
268 | | """Returns the Print Quota information for a given (groupid, printerid).""" |
269 | | result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(cn=*))", ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=groupid) |
| 276 | |
| 277 | def getGroupPQuota(self, grouppquotaid, printerid) : |
| 278 | """Returns the Print Quota information for a given (grouppquotaid, printerid).""" |
| 279 | result = self.doSearch("objectClass=pykotaGroupPQuota", ["pykotaGroupName", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=grouppquotaid, scope=ldap.SCOPE_BASE) |