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 = []
|
candidates = []
|
||||||
seen = set()
|
seen = set()
|
||||||
|
|
||||||
def add(val):
|
def add_location_id(source):
|
||||||
if val is None:
|
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
|
return
|
||||||
s = str(val).strip().lower().replace(' ', '_')
|
|
||||||
if s and s not in seen:
|
try:
|
||||||
seen.add(s)
|
location_id = int(value)
|
||||||
candidates.append(s)
|
except (TypeError, ValueError):
|
||||||
|
return
|
||||||
|
|
||||||
|
if location_id not in seen:
|
||||||
|
seen.add(location_id)
|
||||||
|
candidates.append(location_id)
|
||||||
|
|
||||||
if preferred:
|
if preferred:
|
||||||
add(preferred)
|
try:
|
||||||
|
add_location_id({'id': int(preferred)})
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
sources = []
|
sources = []
|
||||||
try:
|
|
||||||
if profile and profile.connection and profile.connection.location:
|
|
||||||
sources.append(profile.connection.location)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
try:
|
try:
|
||||||
if profile and profile.location:
|
if profile and profile.location:
|
||||||
sources.append(profile.location)
|
sources.append(profile.location)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
if profile and profile.connection and profile.connection.location:
|
||||||
|
sources.append(profile.connection.location)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
for source in sources:
|
for source in sources:
|
||||||
add(getattr(source, 'id', None))
|
add_location_id(source)
|
||||||
add(getattr(source, 'country_name', None))
|
|
||||||
add(getattr(source, 'name', None))
|
|
||||||
add(getattr(source, 'code', None))
|
|
||||||
add(getattr(source, 'country_code', None))
|
|
||||||
|
|
||||||
return candidates
|
return candidates
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ def setup_observers(update_status):
|
||||||
'custom_message', lambda event: update_status(f'{event.subject if event.subject else ""}'))
|
'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('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('sync_done', lambda event: update_status('Ticket prices synced.'))
|
||||||
ticket_observer.subscribe('waiting', lambda event: update_status('Waiting for payment...'))
|
ticket_observer.subscribe('waiting', lambda event: update_status('Waiting for payment...'))
|
||||||
ticket_observer.subscribe('paid', lambda event: update_status('Payment received.'))
|
ticket_observer.subscribe('paid', lambda event: update_status('Payment received.'))
|
||||||
|
|
|
||||||
|
|
@ -231,19 +231,26 @@ class Worker(QObject):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
last_msg = str(e)
|
last_msg = str(e)
|
||||||
continue
|
continue
|
||||||
if not isinstance(outcome, dict):
|
if not isinstance(outcome, Result):
|
||||||
last_msg = 'invalid_response'
|
last_msg = f'Unexpected ticket result type: {type(outcome).__name__}'
|
||||||
continue
|
self._ticket_error_emitted = True
|
||||||
billing_code = outcome.get('billing_code')
|
self.change_page.emit(f'Ticket use failed: {last_msg}', True)
|
||||||
if outcome.get('valid') and billing_code:
|
return None
|
||||||
|
|
||||||
|
billing_code = outcome.data
|
||||||
|
if outcome.valid and billing_code:
|
||||||
self._consumed_ticket = str(which_ticket)
|
self._consumed_ticket = str(which_ticket)
|
||||||
return billing_code
|
return billing_code
|
||||||
if billing_code:
|
if billing_code:
|
||||||
self._consumed_ticket = str(which_ticket)
|
self._consumed_ticket = str(which_ticket)
|
||||||
return billing_code
|
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
|
last_msg = msg
|
||||||
if msg != 'invalid_location':
|
if 'invalid_location' not in msg:
|
||||||
self._ticket_error_emitted = True
|
self._ticket_error_emitted = True
|
||||||
self.change_page.emit(f'Ticket use failed: {msg}', True)
|
self.change_page.emit(f'Ticket use failed: {msg}', True)
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue