@@ -99,6 +99,7 @@ class _Resource(object):
9999 _changes = {}
100100 _includes = ()
101101 _relations = ()
102+ _unconvertible = ()
102103 _readonly = ('id' , 'created_on' , 'updated_on' , 'author' , 'user' , 'project' , 'issue' )
103104 __length_hint__ = None # fixes Python 2.6 list() call on resource object
104105
@@ -121,8 +122,12 @@ def __setitem__(self, item, value):
121122 def __getattr__ (self , item ):
122123 """Returns the requested attribute and makes a conversion if needed"""
123124 if item in self .attributes :
125+ # If item shouldn't be converted let's return it as it is
126+ if item in self ._unconvertible :
127+ return self .attributes [item ]
128+
124129 # If item should be a Resource object, let's convert it
125- if item in _RESOURCE_MAP :
130+ elif item in _RESOURCE_MAP :
126131 manager = ResourceManager (self .manager .redmine , _RESOURCE_MAP [item ])
127132 return manager .to_resource (self .attributes [item ])
128133
@@ -288,6 +293,7 @@ class Project(_Resource):
288293
289294 _includes = ('trackers' , 'issue_categories' )
290295 _relations = ('wiki_pages' , 'memberships' , 'issue_categories' , 'versions' , 'news' , 'issues' )
296+ _unconvertible = ('status' ,)
291297 _readonly = _Resource ._readonly + ('identifier' ,)
292298
293299
@@ -546,14 +552,7 @@ class Version(_Resource):
546552 query_update = '/versions/{0}.json'
547553 query_delete = '/versions/{0}.json'
548554
549- def __getattr__ (self , item ):
550- # We have to return status attribute as it is, otherwise it
551- # will be automatically converted to IssueStatus resource
552- # by the parent _Resource object which is not what we want
553- if item == 'status' :
554- return self .attributes [item ]
555-
556- return super (Version , self ).__getattr__ (item )
555+ _unconvertible = ('status' ,)
557556
558557
559558class User (_Resource ):
@@ -571,20 +570,9 @@ class User(_Resource):
571570 query_delete = '/users/{0}.json'
572571
573572 _includes = ('memberships' , 'groups' )
573+ _unconvertible = ('status' ,)
574574 _readonly = _Resource ._readonly + ('api_key' , 'last_login_on' , 'custom_fields' )
575575
576- def __getattr__ (self , item ):
577- # We have to return status attribute as it is, otherwise it
578- # will be automatically converted to IssueStatus resource
579- # by the parent _Resource object which is not what we want
580- if item == 'status' :
581- try :
582- return self .attributes [item ]
583- except KeyError :
584- return self .action_if_attribute_absent ()
585-
586- return super (User , self ).__getattr__ (item )
587-
588576 def __str__ (self ):
589577 try :
590578 return super (User , self ).__str__ ()
0 commit comments