def _save_to_disk(self, clients): tmp_table_name = self.table_name+'.tmp' with open(tmp_table_name, mode='w') as f: writer = csv.DictWriter(f, fieldnames=ClientModel.shema()) writer.writerows(clients) os.remove(self.table_name) os.rename(tmp_table_name, self.table_name)
def list_clients(self): with open(self.table_name, mode='r') as f: reader = csv.DictReader(f, fieldnames=ClientModel.shema()) return list(reader)
def create_client(self, client): with open(self.table_name, mode='a') as f: writer = csv.DictWriter(f, fieldnames=ClientModel.shema()) writer.writerow(client.to_dic())