- Timestamp:
- 03/10/12 17:05:03 (7 years ago)
- Location:
- mauRepo/MolesManager/trunk/cedaMoles
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/MolesManager/trunk/cedaMoles/MolesManager/djencoder.py
r8599 r8606 10 10 import re 11 11 from decimal import Decimal 12 from inspect import isclass13 12 from sqlalchemy.orm.collections import InstrumentedList 14 13 15 14 class DJEncoder(JSONEncoder): 16 17 15 __PATTERN = re.compile('\D\D__*') 18 16 __PATTERN2 = re.compile('\A\w+__id\Z') … … 24 22 25 23 def default(self, obj): 26 d= {}24 mydict = {} 27 25 28 26 if isinstance(obj, datetime.datetime): … … 40 38 # Convert objects to a dictionary of their representation 41 39 try: 42 d= { '__module__':obj.__module__,40 mydict = { '__module__':obj.__module__, 43 41 } 44 42 except Exception as e: 45 43 print e 46 return d44 return mydict 47 45 if obj.__class__.__name__ == 'EnumSymbol': 48 d['__class__'] = obj._cls.__name__46 mydict['__class__'] = obj._cls.__name__ 49 47 else: 50 d['__class__'] = obj.__class__.__name__48 mydict['__class__'] = obj.__class__.__name__ 51 49 52 if d['__module__'].startswith('sqlalchemy'):53 return d50 if mydict['__module__'].startswith('sqlalchemy'): 51 return mydict 54 52 55 53 for key in obj.__dict__.keys(): … … 57 55 or DJEncoder.__PATTERN.match(key) \ 58 56 or DJEncoder.__PATTERN2.match(key)): 59 d.update({key: getattr(obj, key)})57 mydict.update({key: getattr(obj, key)}) 60 58 getters = list(methodsWithDecorator(type(obj), "property")) 61 59 for name in getters: 62 60 if hasattr(obj, name): 63 61 try: 64 d.update({name: getattr(obj, name)})62 mydict.update({name: getattr(obj, name)}) 65 63 except Exception as e: 66 64 DJEncoder.log.error(e) 67 65 68 for key, value in d.items():66 for key, value in mydict.items(): 69 67 if value is not None: 70 if isinstance(value, list) or isinstance(value, InstrumentedList): 68 if (isinstance(value, list) \ 69 or isinstance(value, InstrumentedList)) \ 70 and not isPrimitive(value): 71 71 for item in value: 72 72 if id(item) in getattr(self, '_DJEncoder__markers'): 73 d.pop(key)73 mydict.pop(key) 74 74 break 75 75 elif id(value) in getattr(self, '_DJEncoder__markers'): 76 d.pop(key)77 return d76 mydict.pop(key) 77 return mydict 78 78 79 79 def iterencode(self, o): … … 114 114 #res = res.replace('(', '(') 115 115 #res = res.replace(')', ')') 116 return res 116 return res 117 118 def isPrimitive(obj): 119 # Is a simple primitive? 120 return obj is None \ 121 or isinstance(obj, str) \ 122 or isinstance(obj, int) \ 123 or isinstance(obj, unicode) \ 124 or isinstance(obj, Decimal) -
mauRepo/MolesManager/trunk/cedaMoles/libs/migration/processor/deployment.py
r8554 r8606 117 117 log.addHandler(StreamHandler()) 118 118 log.setLevel(logging.INFO) 119 def __init__(self, data_entity_migration, deployment_migration, epb Repo):119 def __init__(self, data_entity_migration, deployment_migration, epb_repo): 120 120 ''' 121 121 Initializes the class … … 126 126 self._data_entity_migration = data_entity_migration 127 127 self._deployment_migration = deployment_migration 128 self.epbRepo = epb Repo128 self.epbRepo = epb_repo 129 129 self._dataEntityHasSameHash = has_mo_same_hash(self._data_entity_migration) 130 130 self._deploymentHasSameHash = has_mo_same_hash(self._deployment_migration) … … 222 222 223 223 if py_date: 224 dt = create_date(py_date) 225 ci_date = create_ci_date(getCLValue(CI_DateTypeCode.cl_publication), \ 226 date = dt) 224 c_date = create_date(py_date) 225 ci_date = \ 226 create_ci_date(\ 227 getCLValue(CI_DateTypeCode.cl_publication), \ 228 date = c_date) 227 229 i_authority = create_ci_citation("DOI", date = ci_date) 228 230 identifier = create_md_identifier(code = doi, authority=i_authority)
Note: See TracChangeset
for help on using the changeset viewer.