Create custom column dialog: Fix exception if the library has no custom columns

This commit is contained in:
Charles Haley 2022-01-07 11:54:24 +00:00
parent cc96900aee
commit c44af8e71a
2 changed files with 5 additions and 2 deletions

View File

@ -28,7 +28,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.custcols = copy.deepcopy(db.field_metadata.custom_field_metadata())
for k, cc in self.custcols.items():
cc['original_key'] = k
self.initial_created_count = max(x['colnum'] for x in self.custcols.values()) + 1
# Using max() in this way requires python 3.4+
self.initial_created_count = max((x['colnum'] for x in self.custcols.values()),
default=0) + 1
self.created_count = self.initial_created_count
self.column_up.clicked.connect(self.up_column)

View File

@ -787,7 +787,8 @@ class CreateNewCustomColumn(object):
self.custcols = copy.deepcopy(db.field_metadata.custom_field_metadata())
# Get the largest internal column number so we can be sure that we can
# detect duplicates.
self.created_count = max(x['colnum'] for x in self.custcols.values()) + 1
self.created_count = max((x['colnum'] for x in self.custcols.values()),
default=0) + 1
def create_column(self, lookup_name, column_heading, datatype, is_multiple,
display={}, generate_unused_lookup_name=False, freeze_lookup_name=True):