Fix log table sorting. By @rblenis (#881)

Fixes #880
This commit is contained in:
Robert Blenis 2021-02-21 20:38:35 -05:00 committed by GitHub
parent 563b0a0bb7
commit d701211037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 7 deletions

View File

@ -8,6 +8,14 @@ uifile = get_asset('UI/scheduletab.ui')
ScheduleUI, ScheduleBase = uic.loadUiType(uifile)
class LogTableColumn:
Time = 0
Category = 1
Subcommand = 2
Repository = 3
ReturnCode = 4
class ScheduleTab(ScheduleBase, ScheduleUI, BackupProfileMixin):
def __init__(self, parent=None):
@ -116,15 +124,17 @@ class ScheduleTab(ScheduleBase, ScheduleUI, BackupProfileMixin):
def populate_logs(self):
event_logs = [s for s in EventLogModel.select().order_by(EventLogModel.start_time.desc())]
sorting = self.logTableWidget.isSortingEnabled()
self.logTableWidget.setSortingEnabled(False) # disable sorting while modifying the table.
self.logTableWidget.setRowCount(len(event_logs)) # go ahead and set table length and then update the rows
for row, log_line in enumerate(event_logs):
self.logTableWidget.insertRow(row)
formatted_time = log_line.start_time.strftime('%Y-%m-%d %H:%M')
self.logTableWidget.setItem(row, 0, QTableWidgetItem(formatted_time))
self.logTableWidget.setItem(row, 1, QTableWidgetItem(log_line.category))
self.logTableWidget.setItem(row, 2, QTableWidgetItem(log_line.subcommand))
self.logTableWidget.setItem(row, 3, QTableWidgetItem(log_line.repo_url))
self.logTableWidget.setItem(row, 4, QTableWidgetItem(str(log_line.returncode)))
self.logTableWidget.setRowCount(len(event_logs))
self.logTableWidget.setItem(row, LogTableColumn.Time, QTableWidgetItem(formatted_time))
self.logTableWidget.setItem(row, LogTableColumn.Category, QTableWidgetItem(log_line.category))
self.logTableWidget.setItem(row, LogTableColumn.Subcommand, QTableWidgetItem(log_line.subcommand))
self.logTableWidget.setItem(row, LogTableColumn.Repository, QTableWidgetItem(log_line.repo_url))
self.logTableWidget.setItem(row, LogTableColumn.ReturnCode, QTableWidgetItem(str(log_line.returncode)))
self.logTableWidget.setSortingEnabled(sorting) # restore sorting now that modifications are done
def _draw_next_scheduled_backup(self):
self.nextBackupDateTimeLabel.setText(self.app.scheduler.next_job_for_profile(self.profile().id))