Skip to content

Commit

Permalink
fix: allow reordering more than two dicts/groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Crissium committed Oct 20, 2023
1 parent 41f118b commit 48d7480
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions server/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,12 @@ def reorder_groups(self, groups: 'list[dict[str, str | list[str]]]') -> 'None':
for index, group in enumerate(self.groups):
if group != groups[index]:
changed_indexes.append(index)
# Then ensure only two groups are swapped

if len(changed_indexes) == 0:
return
elif len(changed_indexes) != 2:
raise ValueError('Only two groups can be swapped.')
first, second = changed_indexes
self.groups[first], self.groups[second] = self.groups[second], self.groups[first]

self.groups = groups
logger.info('%d groups are reordered.' % len(changed_indexes))
self._save_groups()

def remove_group(self, group: 'dict[str, str | set[str]]') -> 'None':
Expand Down Expand Up @@ -409,13 +408,12 @@ def reorder_dictionaries(self, dictionaries_info: 'list[dict[str, str]]') -> 'No
for index, dictionary_info in enumerate(self.dictionaries_list):
if dictionary_info != dictionaries_info[index]:
changed_indexes.append(index)
# Then ensure only two dictionaries are swapped

if len(changed_indexes) == 0:
return
elif len(changed_indexes) != 2:
raise ValueError('Only two dictionaries can be swapped.')
first, second = changed_indexes
self.dictionaries_list[first], self.dictionaries_list[second] = self.dictionaries_list[second], self.dictionaries_list[first]

self.dictionaries_list = dictionaries_info
logger.info('%d dictionaries are reordered.' % len(changed_indexes))
self._save_dictionary_list()

def remove_dictionary_from_group(self, dictionary_name: 'str', group_name: 'str') -> 'None':
Expand Down

0 comments on commit 48d7480

Please sign in to comment.