def sync(self): # code below is based on the assumption that bw uses utc timestamps tz = datetime.datetime.now(datetime.timezone.utc).astimezone() time_shift = -tz.utcoffset().total_seconds() data = [] for name in natural_sort(bw.databases): dt = bw.databases[name].get("modified", "") if dt: dt = arrow.get(dt).shift(seconds=time_shift).humanize() # final column includes interactive checkbox which shows read-only state of db database_read_only = project_settings.db_is_readonly(name) data.append({ "Name": name, "Depends": ", ".join(bw.databases[name].get("depends", [])), "Modified": dt, "Records": bc.count_database_records(name), "Read-only": database_read_only, }) self._dataframe = pd.DataFrame(data, columns=self.HEADERS) self.updated.emit()
def sync(self): self.setRowCount(len(bw.databases)) self.setHorizontalHeaderLabels(self.HEADERS) for row, name in enumerate(natural_sort(bw.databases)): self.setItem(row, 0, ABTableItem(name, db_name=name)) depends = bw.databases[name].get('depends', []) self.setItem(row, 1, ABTableItem("; ".join(depends), db_name=name)) dt = bw.databases[name].get('modified', '') if dt: dt = arrow.get(dt).shift(hours=-1).humanize() self.setItem(row, 2, ABTableItem(dt, db_name=name)) self.setItem( row, 3, ABTableItem(str(bw.databases[name].get('number', [])), db_name=name)) self.setItem( row, 4, ABTableItem(None, set_flags=[QtCore.Qt.ItemIsUserCheckable]))
def sync(self): self.setRowCount(len(bw.databases)) self.setHorizontalHeaderLabels(self.HEADERS) for row, name in enumerate(natural_sort(bw.databases)): self.setItem(row, 0, ABTableItem(name, db_name=name)) depends = bw.databases[name].get('depends', []) self.setItem(row, 1, ABTableItem(", ".join(depends), db_name=name)) dt = bw.databases[name].get('modified', '') # code below is based on the assumption that bw uses utc timestamps tz = datetime.datetime.now(datetime.timezone.utc).astimezone() time_shift = -tz.utcoffset().total_seconds() if dt: dt = arrow.get(dt).shift(seconds=time_shift).humanize() self.setItem(row, 2, ABTableItem(dt, db_name=name)) self.setItem( row, 3, ABTableItem(str(len(bw.Database(name))), db_name=name)) self.setItem( row, 4, ABTableItem(None, set_flags=[QtCore.Qt.ItemIsUserCheckable]))
def get_databases_data(databases): """Returns a list with dictionaries that describe the available databases.""" data = [] for row, name in enumerate(natural_sort(databases)): data.append(get_database_metadata(name)) yield data
def test_natural_sort(self): data = ["s100", "s2", "s1"] self.assertEqual(["s1", "s2", "s100"], natural_sort(data))