def _setUpRecords(self): recbuf = Config.getRecordBuffer() if recbuf: # recbuf is not a empty list for buf in recbuf: rdate, rec = buf2record(buf) self.addRecord(rdate, rec) # set record buffer up to default value a empty list. Config.setRecordBuffer(list())
def resetAll(self): """This method reset all the data of the Expense to default status. Be careful when call this method, it should be make a warning message to the user. """ self.rec_m.clear() for key in self.projects: del self.projects[key] Config.setProjectBuffer(dict())
def addRecord(self, rdate, baserec): if self.isSetup: self.rec_m.addItem(rdate, baserec) self._checkProjects(rdate, baserec, act="add") Config.setDefault(baserec) else: buf = record2buf(rdate, baserec) recbuf = Config.getRecordBuffer() recbuf.append(buf) Config.setRecordBuffer(recbuf)
def _setUpProjects(self): projbuf = Config.getProjectBuffer() if projbuf: # projbuf is not a empty dict for name, dictbuf in projbuf.items(): projtype = dictbuf["projtype"] proj = Projects.__dict__[projtype]() proj.import_from_dict(dictbuf) self.projects[name] = proj
""" pyExpenses.RecManip ~~~~~~~~~~~~~~~~~~~ Implements the interface's object that manipulator of records for pyExpenses. :copyright: (c) 2012 by Jason Lai. :license: BSD, see LICENSE for more details. """ from datetime import date, timedelta from ConfigManip import Config import RecManipImpl STORAGE_BACKEND = RecManipImpl.__dict__[Config.getInfo('StorageBackend')] class RecManip(object): def setUp(self, *args, **kwargs): """It's the method really initialize the instance. This should be called after create a instance, the passing arguments can control defferent options. """ self.impl = STORAGE_BACKEND(*args, **kwargs) def updatePassword(self, oldpwd, newpwd): self.impl.updatePassword(oldpwd, newpwd) def cancelPassword(self, oldpwd): from RecManipImpl import DEFAULT_PASSWORD
def saveProjects(self): savebuf = {} for name, proj in self.projects.items(): savebuf[name] = proj.export_to_dict() savebuf[name]["projtype"] = proj.__class__.__name__ Config.setProjectBuffer(savebuf)