hakkoso/persona.py

36 lines
1.1 KiB
Python

"Supposed to be a singleton"
class ManualIntervention():
def __init__(self):
self.intervention_happened = False
self.intervention_required = False
self.response = None
self.number_of_requests = 0
self.options = (('Ok', True),)
self.label = 'È richiesto un intervento manuale'
def set(self, response):
self.response = response
self.intervention_happened = True
return True
def get(self, label=None, options=None):
update = False
if not self.intervention_required:
update = True
self.intervention_required = True
self.label = label or self.label
self.options = options or self.options
self.number_of_requests += 1
return update, self.intervention_happened and self.response
def clear(self):
self.__init__()
return True
def getState(self):
return {
'label': self.label,
'required': self.intervention_required,
'options': tuple({'tag':o[0], 'value':o[1]} for o in self.options)
}