Commit 94d13812 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Globals.getClassFromName updated to make use of zope

parent a3ad96f5
...@@ -155,16 +155,17 @@ def moveExcess(consumption=1,safetyStock=70, giverId=None, receiverId=None): ...@@ -155,16 +155,17 @@ def moveExcess(consumption=1,safetyStock=70, giverId=None, receiverId=None):
# Import a class from a dotted name used in json. # Import a class from a dotted name used in json.
# ======================================================================= # =======================================================================
def getClassFromName(dotted_name): def getClassFromName(dotted_name):
# XXX dotted name is always Dream.Something, but the real class lives in from zope.dottedname.resolve import resolve
# dream.simulation.Something.Something import logging
dream, class_name = dotted_name.split('.') logger = logging.getLogger("dream.platform")
try: parts = dotted_name.split('.')
import dream.simulation as ds # this is added for backwards compatibility
__import__('dream.simulation.%s' % class_name) if dotted_name.startswith('Dream'):
return getattr(getattr(ds, class_name), class_name) class_name = dotted_name.split('.')[-1]
except: new_dotted_name = 'dream.simulation.%s.%s' % (class_name, class_name)
_class=__import__(class_name) logger.info(("Old style name %s used, using %s instead" % (dotted_name, new_dotted_name)))
return getattr(_class,class_name) dotted_name = new_dotted_name
return resolve(dotted_name)
# ======================================================================= # =======================================================================
# returns a method by its name. name should be given as Dream.ClassName.MethodName # returns a method by its name. name should be given as Dream.ClassName.MethodName
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment