diff --git a/gui/v2/actions/disable_profiles.py b/gui/v2/actions/disable_profiles.py old mode 100644 new mode 100755 diff --git a/gui/v2/actions/locations.py b/gui/v2/actions/locations.py index c773f78..47ebf48 100755 --- a/gui/v2/actions/locations.py +++ b/gui/v2/actions/locations.py @@ -2,34 +2,43 @@ def location_candidates(profile, preferred=None): candidates = [] seen = set() - def add(val): - if val is None: + def add_location_id(source): + if isinstance(source, dict): + value = source.get('id') or source.get('location_id') + else: + value = getattr(source, 'id', None) + + if value is None or isinstance(value, bool): return - s = str(val).strip().lower().replace(' ', '_') - if s and s not in seen: - seen.add(s) - candidates.append(s) + + try: + location_id = int(value) + except (TypeError, ValueError): + return + + if location_id not in seen: + seen.add(location_id) + candidates.append(location_id) if preferred: - add(preferred) + try: + add_location_id({'id': int(preferred)}) + except (TypeError, ValueError): + pass sources = [] - try: - if profile and profile.connection and profile.connection.location: - sources.append(profile.connection.location) - except Exception: - pass try: if profile and profile.location: sources.append(profile.location) except Exception: pass + try: + if profile and profile.connection and profile.connection.location: + sources.append(profile.connection.location) + except Exception: + pass for source in sources: - add(getattr(source, 'id', None)) - add(getattr(source, 'country_name', None)) - add(getattr(source, 'name', None)) - add(getattr(source, 'code', None)) - add(getattr(source, 'country_code', None)) + add_location_id(source) return candidates diff --git a/gui/v2/infrastructure/setup_observers.py b/gui/v2/infrastructure/setup_observers.py index e96acf5..1c6a10f 100755 --- a/gui/v2/infrastructure/setup_observers.py +++ b/gui/v2/infrastructure/setup_observers.py @@ -92,6 +92,7 @@ def setup_observers(update_status): 'custom_message', lambda event: update_status(f'{event.subject if event.subject else ""}')) ticket_observer.subscribe('connecting', lambda event: update_status('Connecting to ticket server...')) + ticket_observer.subscribe('preparing', lambda event: update_status(f'{event.subject if event.subject else "Preparing tickets..."}')) ticket_observer.subscribe('sync_done', lambda event: update_status('Ticket prices synced.')) ticket_observer.subscribe('waiting', lambda event: update_status('Waiting for payment...')) ticket_observer.subscribe('paid', lambda event: update_status('Payment received.')) diff --git a/gui/v2/workers/worker.py b/gui/v2/workers/worker.py index 736107f..118efce 100755 --- a/gui/v2/workers/worker.py +++ b/gui/v2/workers/worker.py @@ -231,19 +231,26 @@ class Worker(QObject): except Exception as e: last_msg = str(e) continue - if not isinstance(outcome, dict): - last_msg = 'invalid_response' - continue - billing_code = outcome.get('billing_code') - if outcome.get('valid') and billing_code: + if not isinstance(outcome, Result): + last_msg = f'Unexpected ticket result type: {type(outcome).__name__}' + self._ticket_error_emitted = True + self.change_page.emit(f'Ticket use failed: {last_msg}', True) + return None + + billing_code = outcome.data + if outcome.valid and billing_code: self._consumed_ticket = str(which_ticket) return billing_code if billing_code: self._consumed_ticket = str(which_ticket) return billing_code - msg = outcome.get('message', 'failed') + + msg = outcome.message + if not msg and outcome.error_type: + msg = outcome.error_type.value + msg = msg or 'Ticket use failed.' last_msg = msg - if msg != 'invalid_location': + if 'invalid_location' not in msg: self._ticket_error_emitted = True self.change_page.emit(f'Ticket use failed: {msg}', True) return None