forked from Support/sp-hydra-veil-gui
update: updated ticket observer
This commit is contained in:
parent
05a1000583
commit
0185db0b25
4 changed files with 41 additions and 24 deletions
0
gui/v2/actions/disable_profiles.py
Normal file → Executable file
0
gui/v2/actions/disable_profiles.py
Normal file → Executable file
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.'))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue