Changeset 8480 for mauRepo/MolesManager


Ignore:
Timestamp:
01/08/12 11:17:27 (7 years ago)
Author:
mnagni
Message:

Fixed a bug in objectEncoding

Location:
mauRepo/MolesManager/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/djencoder.py

    r8433 r8480  
    55''' 
    66from json.encoder import JSONEncoder 
    7 from MolesManager.forms.date import methodsWithDecorator 
    87import re 
    98import logging 
     9import inspect 
    1010 
    1111class DJEncoder(JSONEncoder): 
     
    5050                #return {} 
    5151            else: 
    52                 self.__markers[id(value)] = value 
    5352                if isinstance(value, str) or isinstance(value, unicode):                     
    5453                    self.__markers[id(value)] = escapeForJSON(value) 
     
    5655                    self.__markers[id(value)] = value 
    5756        return d 
     57 
     58def methodsWithDecorator(cls, decoratorName): 
     59    #if type(cls).__name__ == 'type' or type(cls).__name__ == 'instancemetho': 
     60    #    return  
     61    sourcelines = inspect.getsourcelines(cls)[0] 
     62    for i,line in enumerate(sourcelines): 
     63        line = line.strip() 
     64        if line.split('(')[0].strip() == '@'+decoratorName: # leaving a bit out 
     65            nextLine = sourcelines[i+1] 
     66            name = nextLine.split('def')[1].split('(')[0].strip() 
     67            yield(name) 
    5868 
    5969def encodeToJSON(toEncode): 
  • mauRepo/MolesManager/trunk/src/MolesManager/forms/date.py

    r8476 r8480  
    2323    pass 
    2424     
    25 def methodsWithDecorator(cls, decoratorName): 
    26     if type(cls).__name__ == 'type' or type(cls).__name__ == 'instancemetho': 
    27         return  
    28     sourcelines = inspect.getsourcelines(cls)[0] 
    29     for i,line in enumerate(sourcelines): 
    30         line = line.strip() 
    31         if line.split('(')[0].strip() == '@'+decoratorName: # leaving a bit out 
    32             nextLine = sourcelines[i+1] 
    33             name = nextLine.split('def')[1].split('(')[0].strip() 
    34             yield(name) 
    35  
    36  
    3725class Model2Form(object): 
    3826    def __init__(self, obj = None, mapper = None): 
  • mauRepo/MolesManager/trunk/src/MolesManager/views/moles2gui/__init__.py

    r8477 r8480  
    99import operator 
    1010import inspect 
     11from libs.epb import isPrimitive 
    1112 
    1213""" 
     
    305306        return ret 
    306307    else: 
    307         return _encodeCedaMoles2Adapter(newobj)             
    308      
    309 def _isPrimitive(obj): 
    310     # Is a simple primitive? 
    311     return obj is None \ 
    312             or isinstance(obj, str) \ 
    313             or isinstance(obj, int) \ 
    314             or isinstance(obj, unicode) 
    315      
     308        return _encodeCedaMoles2Adapter(newobj)               
    316309     
    317310def _encodeCedaMoles2Adapter(cedaObj): 
    318     if _isPrimitive(cedaObj): 
     311    if isPrimitive(cedaObj): 
    319312        return cedaObj 
    320313     
     
    332325    decJson = json 
    333326     
    334     if _isPrimitive(decJson) and not isinstance(decJson, str): 
     327    if isPrimitive(decJson) and not isinstance(decJson, str): 
    335328        return decJson  
    336329     
  • mauRepo/MolesManager/trunk/src/libs/epb.py

    r8460 r8480  
    3333from sqlalchemy.orm import subqueryload 
    3434from sqlalchemy.sql.expression import text 
    35 from MolesManager.forms.date import methodsWithDecorator 
    3635from sqlalchemy.orm.util import identity_key 
     36from MolesManager.djencoder import methodsWithDecorator 
    3737 
    3838class EPB(object): 
     
    206206    @classmethod 
    207207    def _drillALLData(cls, obj): 
    208         if obj is None: 
     208        if obj is None or isPrimitive(obj): 
    209209            return 
     210         
    210211        if isinstance(obj, list): 
    211212            for element in obj: 
     
    222223                    pass 
    223224         
     225def isPrimitive(obj): 
     226    # Is a simple primitive? 
     227    return obj is None \ 
     228            or isinstance(obj, str) \ 
     229            or isinstance(obj, int) \ 
     230            or isinstance(obj, unicode) 
Note: See TracChangeset for help on using the changeset viewer.