From 0cc496a40bf9e142163751c736a739eb1928e9ff Mon Sep 17 00:00:00 2001 From: JOhn Date: Mon, 24 Aug 2026 18:26:25 -0400 Subject: [PATCH] update: updated ticketing logic from gui --- gui/v2/actions/disable_profiles.py | 0 gui/v2/actions/locations.py | 35 -------- .../ui/pages/ticket_or_billing_choice_page.py | 18 ++--- gui/v2/workers/ticketing_worker_thread.py | 11 --- gui/v2/workers/worker.py | 81 ++++++++++--------- 5 files changed, 46 insertions(+), 99 deletions(-) mode change 100644 => 100755 gui/v2/actions/disable_profiles.py delete mode 100755 gui/v2/actions/locations.py 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 deleted file mode 100755 index c773f78..0000000 --- a/gui/v2/actions/locations.py +++ /dev/null @@ -1,35 +0,0 @@ -def location_candidates(profile, preferred=None): - candidates = [] - seen = set() - - def add(val): - if val is None: - return - s = str(val).strip().lower().replace(' ', '_') - if s and s not in seen: - seen.add(s) - candidates.append(s) - - if preferred: - add(preferred) - - 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 - - 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)) - - return candidates diff --git a/gui/v2/ui/pages/ticket_or_billing_choice_page.py b/gui/v2/ui/pages/ticket_or_billing_choice_page.py index d32a648..8ae4914 100755 --- a/gui/v2/ui/pages/ticket_or_billing_choice_page.py +++ b/gui/v2/ui/pages/ticket_or_billing_choice_page.py @@ -1,10 +1,8 @@ from PyQt6.QtWidgets import QLabel, QListWidget, QListWidgetItem, QPushButton from PyQt6 import QtCore -from core.controllers.ProfileController import ProfileController from core.controllers.tickets.UseTicketController import get_unused_tickets -from gui.v2.actions.locations import location_candidates from gui.v2.infrastructure.setup_observers import ticket_observer from gui.v2.ui.pages.Page import Page @@ -91,20 +89,14 @@ class TicketOrBillingChoicePage(Page): self.status_label.setText("Pick a ticket from the list first.") return which_ticket = item.data(QtCore.Qt.ItemDataRole.UserRole) - profile_id = self.update_status.current_profile_id try: - profile = ProfileController.get(int(profile_id)) - except Exception: - profile = None - candidates = location_candidates(profile) - if not candidates: - self.status_label.setText("Could not determine profile location.") + profile_id = int(self.update_status.current_profile_id) + except (TypeError, ValueError): + self.status_label.setText("Could not determine profile.") return profile_data = { - 'id': int(profile_id), - 'use_ticket': which_ticket, - 'ticket_location': candidates[0], - 'profile': profile + 'id': profile_id, + 'use_ticket': which_ticket } menu_page = self.custom_window.navigator.get_cached("menu") if menu_page: diff --git a/gui/v2/workers/ticketing_worker_thread.py b/gui/v2/workers/ticketing_worker_thread.py index 1ea0d74..a8ac19d 100755 --- a/gui/v2/workers/ticketing_worker_thread.py +++ b/gui/v2/workers/ticketing_worker_thread.py @@ -7,7 +7,6 @@ from core.controllers.tickets.FailedVerificationController import ( evaluate_if_its_the_key, prepare_tickets_with_saved_blind_sigs, ) -from core.controllers.tickets.UseTicketController import use_ticket from gui.v2.infrastructure.setup_observers import ( connection_observer, @@ -22,7 +21,6 @@ class TicketingWorkerThread(QThread): not_paid = pyqtSignal() paid_check_failed = pyqtSignal(str) prep_done = pyqtSignal(object) - use_done = pyqtSignal(object) failed_verification_evaluated = pyqtSignal(object) saved_blind_prep_done = pyqtSignal(object) error = pyqtSignal(str) @@ -71,14 +69,5 @@ class TicketingWorkerThread(QThread): elif self.action == 'PREPARE_SAVED_BLIND_SIGS': result = prepare_tickets_with_saved_blind_sigs(ticket_observer, connection_observer) self.saved_blind_prep_done.emit(result) - elif self.action == 'USE_TICKET': - result = use_ticket( - which_ticket=self.params['which_ticket'], - which_location=self.params['which_location'], - ticket_observer=ticket_observer, - connection_observer=connection_observer, - profile=self.params['profile'] - ) - self.use_done.emit(result) except Exception as e: self.error.emit(str(e)) diff --git a/gui/v2/workers/worker.py b/gui/v2/workers/worker.py index 736107f..264f352 100755 --- a/gui/v2/workers/worker.py +++ b/gui/v2/workers/worker.py @@ -24,7 +24,6 @@ from core.Errors import ( UnsupportedApplicationVersionError, ) -from gui.v2.actions.locations import location_candidates from gui.v2.actions.database_health import GuiStorageDatabaseError from gui.v2.infrastructure.screen_size import get_max_screensize from gui.v2.infrastructure.setup_observers import ( @@ -70,8 +69,7 @@ class Worker(QObject): if 'use_ticket' in self.profile_data: ticket_billing_code = self._consume_ticket( - self.profile_data['use_ticket'], - self.profile_data.get('ticket_location')) + self.profile_data['use_ticket']) if ticket_billing_code is None: return self.profile_data['billing_code'] = ticket_billing_code @@ -170,9 +168,6 @@ class Worker(QObject): return None - def _location_candidates(self, preferred=None): - return location_candidates(self.profile, preferred) - def _profile_has_valid_subscription(self): try: sub = getattr(self.profile, 'subscription', None) @@ -209,47 +204,53 @@ class Worker(QObject): return None if which_ticket is None or which_ticket == 'error': return None - return self._consume_ticket(which_ticket, None) + return self._consume_ticket(which_ticket) - def _consume_ticket(self, which_ticket, which_location): - candidates = self._location_candidates(preferred=which_location) - if not candidates: + def _ticket_location_id(self): + location = getattr(self.profile, 'location', None) + location_id = getattr(location, 'id', None) + if location_id is None: + return None + location_id = str(location_id).strip() + if not location_id: + return None + return location_id + + def _consume_ticket(self, which_ticket): + which_location = self._ticket_location_id() + if which_location is None: self._ticket_error_emitted = True self.change_page.emit('Could not determine profile location for ticket use.', True) return None - last_msg = None - for cand in candidates: - try: - outcome = use_ticket( - which_ticket=which_ticket, - which_location=cand, - ticket_observer=ticket_observer, - connection_observer=connection_observer, - profile=self.profile - ) - 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: - 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') - last_msg = msg - if msg != 'invalid_location': - self._ticket_error_emitted = True - self.change_page.emit(f'Ticket use failed: {msg}', True) - return None + try: + outcome = use_ticket( + which_ticket=which_ticket, + which_location=which_location, + ticket_observer=ticket_observer, + connection_observer=connection_observer, + profile=self.profile + ) + except Exception as e: + self._ticket_error_emitted = True + self.change_page.emit(f'Ticket use failed: {e}', True) + return None + + if not isinstance(outcome, dict): + self._ticket_error_emitted = True + self.change_page.emit('Ticket use failed: invalid_response', True) + return None + + billing_code = outcome.get('billing_code') + if outcome.get('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 self._ticket_error_emitted = True - self.change_page.emit(f'Ticket use failed: {last_msg or "no valid location"}', True) + self.change_page.emit(f'Ticket use failed: {outcome.get("message", "failed")}', True) return None def handle_profile_status(self, profile, is_enabled):