diff --git a/tladm/modules/thinlinc/tlwebadm/locations.py b/tladm/modules/thinlinc/tlwebadm/locations.py index ca53f5553..25829dfc9 100644 --- a/tladm/modules/thinlinc/tlwebadm/locations.py +++ b/tladm/modules/thinlinc/tlwebadm/locations.py @@ -77,25 +77,26 @@ class WebAdminSection(WebAdminSectionBase): ("", False, [])) selected_location = newloc[0] search_list['new_name'] = "New location" + search_list['new_location'] = True elif selected_location and search_list['new_name']: newloc = self.location_from_query(query) # Rename? if search_list['new_name'] != selected_location: newloc = (selected_location, newloc[1]) - - if newloc: - if newloc[0] not in locations: search_list['new_location'] = True + elif selected_location and selected_location not in locations: + search_list['new_location'] = True + + if newloc: locations[newloc[0]] = newloc[1] - # FIXME: One reason that selected_location is missing from locations is - # that it is new, has empty new_name and has not been saved yet. Bug 8123. - if selected_location is not None and selected_location in locations: + if selected_location is not None: search_list["all_printers"] = self._get_current_printerlist() - search_list["details"] = {'location': selected_location, - 'description': locations[selected_location][0], - 'unknown': locations[selected_location][1], - 'printers': locations[selected_location][2]} + details = locations.get(selected_location, ["", False, []]) + search_list["details"] = { 'location': selected_location, + 'description': details[0], + 'unknown': details[1], + 'printers': details[2] } search_list['locations'] = sorted(self.dict_to_list(locations), key = lambda t: locale.strxfrm(t[0])) diff --git a/tladm/tests/test_locations.py b/tladm/tests/test_locations.py index 72fc9ae69..e0135bc1e 100755 --- a/tladm/tests/test_locations.py +++ b/tladm/tests/test_locations.py @@ -356,10 +356,14 @@ class LocationsTest(BaseTestClass): detailed_location = {'description': '', 'location': '__new_entry_1234', 'printers': [], 'unknown': False} wanted_restult = {'add_printer': False, - 'details': None, + 'all_printers': ['my_printer'], + 'details': {'description': '', + 'location': '__new_entry_1234', + 'printers': [], + 'unknown': False}, 'errors': ['Location name is required.'], 'locations': [], - 'new_location': False, + 'new_location': True, 'new_name': ''} self.assertDictEqual(wanted_restult, result)