mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
* Fixed a bug that makes all Instances of a specific "UserInterface" to share same "instance fields". This could be a problem if two access are done simultaneously (for example, 2 services of same type, or two authenticators of same class). Now every new "object" has its own UserInterface objects
* Changed the way the "EditList" are returned, now they are "lists", not "choices" As always, a bit of refactoring
This commit is contained in:
parent
3ec517c90f
commit
ad69d8fa6c
@ -94,6 +94,10 @@ class gui(object):
|
||||
res.append( { 'id' : v, 'text' : '' } )
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def convertToList(vals):
|
||||
return [ unicode(v) for v in vals ]
|
||||
|
||||
@staticmethod
|
||||
def choiceItem(id_, text):
|
||||
'''
|
||||
@ -198,8 +202,6 @@ class gui(object):
|
||||
|
||||
DEFAULT_LENTGH = 32 #: If length of some fields are not especified, this value is used as default
|
||||
|
||||
|
||||
|
||||
def __init__(self, **options):
|
||||
self._data = {
|
||||
'length' : options.get('length', gui.InputField.DEFAULT_LENTGH),
|
||||
@ -638,7 +640,7 @@ class gui(object):
|
||||
|
||||
def __init__(self, **options):
|
||||
super(self.__class__, self).__init__(**options)
|
||||
self._data['values'] = gui.convertToChoices(options['values']) if options.has_key('values') else []
|
||||
self._data['values'] = gui.convertToList(options['values']) if options.has_key('values') else []
|
||||
self._type(gui.InputField.EDITABLE_LIST)
|
||||
|
||||
def _setValue(self, values):
|
||||
@ -646,7 +648,7 @@ class gui(object):
|
||||
So we can override value setting at descendants
|
||||
'''
|
||||
super(self.__class__, self)._setValue(values)
|
||||
self._data['values'] = gui.convertToChoices(values)
|
||||
self._data['values'] = gui.convertToList(values)
|
||||
|
||||
|
||||
|
||||
@ -680,9 +682,17 @@ class UserInterface(object):
|
||||
__metaclass__ = UserInterfaceType
|
||||
|
||||
def __init__(self, values = None):
|
||||
import copy
|
||||
#: If there is an array of elements to initialize, simply try to store values on form fields
|
||||
# Generate a deep copy of inherited Gui, so each User Interface instance has its own "field" set, and do not share the "fielset" with others, what can be really dangerous
|
||||
# Till now, nothing bad happened cause there where being used "serialized", but this do not have to be this way
|
||||
self._gui = copy.deepcopy(self._gui)
|
||||
for key, val in self._gui.iteritems():
|
||||
setattr(self, key, val)
|
||||
|
||||
if values is not None:
|
||||
for k, v in self._gui.iteritems():
|
||||
|
||||
if values.has_key(k):
|
||||
v.value = values[k]
|
||||
|
||||
@ -737,7 +747,9 @@ class UserInterface(object):
|
||||
'''
|
||||
dic = {}
|
||||
for k, v in self._gui.iteritems():
|
||||
if v.isType(gui.InputField.EDITABLE_LIST) or v.isType(gui.InputField.MULTI_CHOICE_TYPE):
|
||||
if v.isType(gui.InputField.EDITABLE_LIST):
|
||||
dic[k] = gui.convertToList(v.value)
|
||||
elif v.isType(gui.InputField.MULTI_CHOICE_TYPE):
|
||||
dic[k] = gui.convertToChoices(v.value)
|
||||
else:
|
||||
dic[k] = v.value
|
||||
@ -823,11 +835,15 @@ class UserInterface(object):
|
||||
This will only happen (not to be None) in Services.
|
||||
'''
|
||||
logger.debug('Active languaje for gui translation: {0}'.format(get_language()))
|
||||
gui = cls
|
||||
if obj is not None:
|
||||
obj.initGui() # We give the "oportunity" to fill necesary gui data before providing it to client
|
||||
gui = obj
|
||||
|
||||
res = []
|
||||
for key, val in cls._gui.iteritems():
|
||||
for key, val in gui._gui.iteritems():
|
||||
logger.debug('{0} ### {1}'.format(key, val))
|
||||
res.append( { 'name' : key, 'gui' : val.guiDescription(), 'value' : '' }, )
|
||||
|
||||
logger.debug('>>>>>>>>>>>> Gui Description: {0} -- {1}'.format(obj, res))
|
||||
return res
|
||||
|
@ -143,6 +143,10 @@ class OVirtLinkedService(Service):
|
||||
raise Service.ValidationException(_('The length of basename plus length must not be greater than 15'))
|
||||
if self.baseName.value.isdigit():
|
||||
raise Service.ValidationException(_('The machine name can\'t be only numbers'))
|
||||
if int(self.memory.value) < 256:
|
||||
raise Service.ValidationException(_('The minimum allowed memory is 256 Mb'))
|
||||
if int(self.memoryGuaranteed.value) > int(self.memory.value):
|
||||
self.memoryGuaranteed.value = self.memory.value
|
||||
|
||||
def initGui(self):
|
||||
'''
|
||||
|
@ -70,7 +70,7 @@ class IPMachinesService(services.Service):
|
||||
|
||||
|
||||
def valuesDict(self):
|
||||
return { 'ipList' : gui.convertToChoices(self._ips) }
|
||||
return { 'ipList' : gui.convertToList(self._ips) }
|
||||
|
||||
def marshal(self):
|
||||
self.storage().saveData('ips', cPickle.dumps(self._ips))
|
||||
|
@ -46,7 +46,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
ADMIN_AUTH = '#'
|
||||
|
||||
CLIENT_VERSION_REQUIRED = '1.2.0'
|
||||
CLIENT_VERSION_REQUIRED = '1.4.0'
|
||||
|
||||
class Credentials(object):
|
||||
'''
|
||||
|
@ -105,8 +105,8 @@ def getAllServices(credentials):
|
||||
val = dictFromService(serv)
|
||||
val['name'] = serv.provider.name + '\\' + val['name']
|
||||
res.append(val)
|
||||
except Exception, e:
|
||||
logger.debug(e)
|
||||
except:
|
||||
logger.exception('getAllServices')
|
||||
return res
|
||||
|
||||
@needs_credentials
|
||||
@ -141,6 +141,7 @@ def getService(credentials, id):
|
||||
valtext = 'values'
|
||||
val = {'name' : key, valtext : value }
|
||||
res.append(val)
|
||||
logger.debug('getService res: {0}'.format(res))
|
||||
return res
|
||||
|
||||
@needs_credentials
|
||||
|
@ -39,19 +39,22 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def dictFromData(data):
|
||||
'''
|
||||
This function converts an array of dicts of type { 'name' : ..., 'value' : ...} to a single dict where keys are the "name"s and the values are the "value"s
|
||||
This function converts an array of dicts of type { 'name' : ..., 'value' : ...} to a single dictionary where keys are the "name"s and the values are the "value"s
|
||||
example:
|
||||
data = [ { 'name' : 'var1', 'value' : 'value1' }, { 'name' : 'var2', 'value' : 'value2' }, 'name' : 'var3', 'values' : [ ...] ]
|
||||
this will return { 'var1' : 'value1', 'var2' : 'value2' }
|
||||
'''
|
||||
dict = {}
|
||||
dictionary = {}
|
||||
for val in data:
|
||||
if val.has_key('value'):
|
||||
dict[val['name']] = val['value']
|
||||
dictionary[val['name']] = val['value']
|
||||
else:
|
||||
ary = []
|
||||
for value in val['values']:
|
||||
ary.append(value['id'])
|
||||
dict[val['name']] = ary
|
||||
logger.debug("Dictionary obtained: {0} from {1}".format(dict, data))
|
||||
return dict
|
||||
if isinstance(value, dict):
|
||||
ary.append(value['id'])
|
||||
else:
|
||||
ary.append(value)
|
||||
dictionary[val['name']] = ary
|
||||
logger.debug("Dictionary obtained: {0} from {1}".format(dictionary, data))
|
||||
return dictionary
|
Loading…
Reference in New Issue
Block a user