def fill(self,wholeTree=True): if self.id == -1: raise Exception("Correct project.id is not set.") sql = "select * from project where id=?" row = Database().get_one_record(sql,[self.id,]) if row != None: #self.id = int(row["id"]) self.name = row["name"] self.owner = int(row["ownerId"]) self.dtFrom = datetime.strptime(row["dtFrom"], "%Y-%m-%d") self.dtTo = datetime.strptime(row["dtTo"], "%Y-%m-%d") if row["folderId"] != None: self.folderId = int(row["folderId"]) if wholeTree: sql = "select * from engine where projectId=?" engines = Database().get_records(sql,[self.id,]) sql = "select job.* from job inner join engine on " + \ " job.engineId = engine.id where engine.projectId = ?" jobs = Database().get_records(sql,[self.id,]) for r in engines: e = Engine(r) eJobs = [j for j in jobs if int(j["engineId"]) == e.id] for job in eJobs: e.addJob(Job(job)) self.addEngine(e)
def _create_project_tree(self): tree = [] sql = "select * from folder where userId=? order by parent,id" db = Database() dirs = db.get_records(sql, [ self.userId, ]) tree.append(Node(0, "root", "d")) for d in dirs: if d["parent"] == None: id = 0 else: id = int(d["parent"]) n = self._find_in_nodes(tree, id, "d") if n: n.children.append(Node(int(d["id"]), d["name"], "d")) else: raise Exception("Uzel id=" + str(id) + " nenalezen.") sql = "select id,name,folderId from project where ownerId=? order by folderId" rows = db.get_records(sql, [ self.userId, ]) for r in rows: folder = r["folderId"] if not folder: folder = "0" n = self._find_in_nodes(tree, int(folder), "d") if n: n.children.append(Node(int(r["id"]), r["name"], "p")) else: raise Exception("Uzel id=" + str(folder) + " nenalezen.") self.tree = tree
def get_db_object(self): config = configparser.ConfigParser() config.read('config.ini') debug_mode = int(config['DEFAULT']['debugMode']) if not debug_mode: return Database() else: return MockDatabase()
def login(self, username, password): sql = "select * from user where username=? and password=?" row = Database().get_one_record(sql, [username, password]) if row != None: self.id = int(row["id"]) self.name = row["name"] self.surname = row["surname"] self.username = row["username"] self.projectTree = FolderTree(self.id)
def rename_node(self, node, new_name): sql = "" db = Database() if node.is_it_dir: sql = "update folder set name=? where id=?" else: sql = "update project set name=? where id=?" db.run(sql, [new_name, node.id])
def add_node(self, node, parentId): sql = "" params = [] db = Database() if node.is_it_dir: sql = "insert into folder(name,parent,userId) values(?,?,?)" params = [node.name, parentId, self.userId] else: sql = "insert into project(name,ownerId,folderId,dtFrom,dtTo)" \ " values(?,?,?,?,?)" params = [ node.name, self.userId, parentId, node.extra_properties["dtFrom"], node.extra_properties["dtTo"] ] db.run(sql, params)
def job_enddate_test(): sql = "select * from job where id=?" row = Database().get_one_record(sql, [ 3, ]) job = Job(row) print(job) print("end=" + str(job.end)) dtFrom = datetime.strptime("2015-01-01", "%Y-%m-%d") dtTo = datetime.strptime("2015-06-30", "%Y-%m-%d") rozsah = DateRange(dtFrom, dtTo) lst = rozsah.get_range_days() print("nalezeno dni:" + str(len(lst))) counter = 1 for i, d in enumerate(lst): if d >= datetime.strptime("2015-01-14", "%Y-%m-%d"): print(str(counter) + " -> " + str(d)) counter += 1
def get_job_project(self): sql = "select project.* from engine inner join project on engine.projectId=" \ "project.id where engine.id=?" row = Database().get_one_record(sql,[self.engine,]) return row
def _read_svatky(self): #kdyz neni nastaveno nacti z db sql = "select day from svatek order by day" recs = Database().get_records(sql,[]) for r in recs: self._svatky.append(datetime.strptime(r["day"], "%Y-%m-%d"))