Пример #1
0
 def __handle_string_field(self, resource, field):
     '''
     Handle fields of type string
     '''
     args      = field.split()
     attribute = getattr( resource, args[0], None )
     if is_method( attribute ):
         return self.__handle_method_field( attribute, args[1:] )
     return {args[0]: self.__serialize( attribute )}
Пример #2
0
 def handle_field_type(self, resource, field_name, field_type):
     """
     Handle field_names of type string
     """
     args = field_name.split()
     attribute = getattr(resource, args[0], None)
     if is_method(attribute):
         attribute = attribute(*args[1:])
     try:
         if field_type is URI:
             return {args[0]: field_type(attribute, self.api)}
         if field_type is Link:
             pk, link = field_type(attribute, self.api)
             self.links[args[0]] = link
             return {args[0]: pk}
     except (NoReverseMatch, NoResourceMatch):
         return {args[0]: None}
     return {args[0]: field_type(attribute)}