Example #1
0
 def __getattr__(self, name):
     """This function tries to get the given attribute of the item if
     it can not be found using the usual way to get attributes. In
     this case we will split the attribute name by "." and try to get
     the attribute along the "." separated attribute name."""
     data = getattr(self, 'data')
     if data:
         # In some cases it is needed to be able to trigger getting the
         # exapanded value without calling the get_value method. This can
         # be achieved by accessing the attribute with a special name.
         # Lets say you want to get the expanded value for `foo`. You get
         # this by asking for `foo__e_x_p_a_n_d`
         if name.endswith("__e_x_p_a_n_d"):
             return self.get_value(name.replace("__e_x_p_a_n_d", ""),
                                   expand=True)
         elif name.find(".") < 0:
             json_data = json.loads(getattr(self, 'data'))
             if name in json_data:
                 json_value = json_data[name]
                 # Poor mans data type conversion.
                 if isinstance(json_value, basestring):
                     # Try to convert the value into a date object if it
                     # looks like a date.
                     if re_date.match(json_value):
                         return to_date(json_value)
                 return json_value
     return get_raw_value(self, name)
Example #2
0
File: base.py Project: toirl/ringo
 def __getattr__(self, name):
     # In some cases it is needed to be able to trigger getting the
     # exapanded value without calling the get_value method. This can
     # be achieved by accessing the attribute with a special name.
     # Lets say you want to get the expanded value for `foo`. You get
     # this by asking for `foo__e_x_p_a_n_d`
     if name.endswith("__e_x_p_a_n_d"):
         return self.get_value(name.replace("__e_x_p_a_n_d", ""),
                               expand=True)
     return get_raw_value(self, name)
Example #3
0
 def __getattr__(self, name):
     # In some cases it is needed to be able to trigger getting the
     # exapanded value without calling the get_value method. This can
     # be achieved by accessing the attribute with a special name.
     # Lets say you want to get the expanded value for `foo`. You get
     # this by asking for `foo__e_x_p_a_n_d`
     if name.endswith("__e_x_p_a_n_d"):
         return self.get_value(name.replace("__e_x_p_a_n_d", ""),
                               expand=True)
     return get_raw_value(self, name)
Example #4
0
 def __getattr__(self, name):
     """This function tries to get the given attribute of the item if
     it can not be found using the usual way to get attributes. In
     this case we will split the attribute name by "." and try to get
     the attribute along the "." separated attribute name."""
     data = getattr(self, 'data')
     if data:
         json_data = json.loads(getattr(self, 'data'))
         if name in json_data:
             return json_data[name]
     return get_raw_value(self, name)