def _save_to_disk(self, updated_clients): tmp_table_name = self.table_name + '.tmp' with open(tmp_table_name) as f: writer = csv.DictWriter(f, fieldnames=ClientModel.schema()) writer.writerows(updated_clients) os.remove(self.table_name) os.rename(tmp_table_name, self.table_name)
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, ClientModel.schema()) writer.writerows(clients) os.remove(self.table_name) os.rename(tmp_table_name, self.table_name)
def list_clients(self): try: with open(self.table_name, mode='r') as f: reader = csv.DictReader(f, fieldnames=ClientModel.schema()) return list(reader) except: click.echo('There are no clients.') return 0
def _save_to_disk(self, clients): tmp_file_name = self.file_name + ".tmp" with open(tmp_file_name, mode="a") as f: writer = csv.DictWriter(f, fieldnames=ClientModel.schema()) writer.writerows(clients) os.remove(self.file_name) os.rename(tmp_file_name, self.file_name)
def _save_to_disk(self, clients): # creamos tabla temporal tmp_table = self.table_name + '.tmp' with open(tmp_table, mode='w') as f: writer = csv.DictWriter(f, fieldnames=ClientModel.schema()) writer.writerows(clients) # borramos tabla original os.remove(self.table_name) # renombramos nueva tabla os.rename(tmp_table, self.table_name)
def list_clients(self): with open(self.table_name, mode='r') as f: reader = csv.DictReader(f, fieldnames=ClientModel.schema()) return list(reader)
def create_client(self, client): with open(self.table_name, mode='a') as f: writer = csv.DictWriter(f, fieldnames=ClientModel.schema()) writer.writerow(client.to_dict())