from datetime import datetime import geruecht.controller.databaseController as dc import geruecht.controller.emailController as ec from geruecht.logger import getDebugLogger db = dc.DatabaseController() emailController = ec.EmailController() debug = getDebugLogger() class Base: def autoLock(self, user): debug.info("start autolock of user {{ {} }}".format(user)) if user.autoLock: debug.debug("autolock is active") credit = user.getGeruecht(year=datetime.now().year).getSchulden() limit = -1*user.limit if credit <= limit: debug.debug( "credit {{ {} }} is more than user limit {{ {} }}".format(credit, limit)) debug.debug("lock user") user.updateData({'locked': True}) debug.debug("send mail to user") emailController.sendMail(user) else: debug.debug( "cretid {{ {} }} is less than user limit {{ {} }}".format(credit, limit)) debug.debug("unlock user") user.updateData({'locked': False}) db.updateUser(user) def addAmount(self, username, amount, year, month, finanzer=False, bar=False): debug.info("add amount {{ {} }} to user {{ {} }} no month {{ {} }}, year {{ {} }}".format( amount, username, month, year)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) if user.uid == 'extern': debug.debug("user is extern user, so exit add amount") return if not user.locked or finanzer: debug.debug("user is not locked {{ {} }} or is finanzer execution {{ {} }}".format( user.locked, finanzer)) user.addAmount(amount, year=year, month=month) if bar: user.last_seen = datetime.now() db.updateLastSeen(user, user.last_seen) creditLists = user.updateGeruecht() debug.debug("creditList is {{ {} }}".format(creditLists)) for creditList in creditLists: debug.debug("update creditlist {{ {} }}".format(creditList)) db.updateCreditList(creditList) debug.debug("do autolock") self.autoLock(user) retVal = user.getGeruecht(year) debug.debug("updated creditlists is {{ {} }}".format(retVal)) return retVal def addCredit(self, username, credit, year, month): debug.info("add credit {{ {} }} to user {{ {} }} on month {{ {} }}, year {{ {} }}".format( credit, username, month, year)) user = self.getUser(username) debug.debug("user is {{ {} }}".format(user)) if user.uid == 'extern': debug.debug("user is extern user, so exit add credit") return user.addCredit(credit, year=year, month=month) creditLists = user.updateGeruecht() debug.debug("creditlists are {{ {} }}".format(creditLists)) for creditList in creditLists: debug.debug("update creditlist {{ {} }}".format(creditList)) db.updateCreditList(creditList) debug.debug("do autolock") self.autoLock(user) retVal = user.getGeruecht(year) debug.debug("updated creditlists are {{ {} }}".format(retVal)) return retVal def __updateGeruechte(self, user): debug.debug("update creditlists") user.getGeruecht(datetime.now().year) creditLists = user.updateGeruecht() debug.debug("creditlists are {{ {} }}".format(creditLists)) if user.getGeruecht(datetime.now().year).getSchulden() != 0: for creditList in creditLists: debug.debug("update creditlist {{ {} }}".format(creditList)) db.updateCreditList(creditList)