def render(self): if not getattr(self, '_rendered_drawing', None): kwargs = { 'value': self.get_object_value(), 'barWidth': self.width, 'barHeight': self.height, } if self.type in ( 'EAN13', 'EAN8', ): self._rendered_drawing = createBarcodeDrawing( self.type, **kwargs) else: cls = BARCODE_CLASSES[self.type] kwargs['checksum'] = self.checksum if self.type in ('USPS_4State', ): kwargs['routing'] = get_attr_value(self.instance, self.routing_attribute) self._rendered_drawing = cls(**kwargs) return self._rendered_drawing
def get_object_value(self, instance=None, attribute_name=None): """Return the attribute value for just an object""" instance = instance or self.instance attribute_name = attribute_name or self.attribute_name # Checks lambda and instance if self.get_value and instance: try: return self.get_value(self, instance) except TypeError: return self.get_value(instance) # Checks this is an expression tokens = EXP_TOKENS.split(attribute_name) tokens = filter(bool, tokens) # Cleans empty parts if len(tokens) > 1: values = {} for token in tokens: if not token in ('+','-','*','/','**') and not token.isdigit(): values[token] = self.get_object_value(instance, token) return eval(attribute_name, values) # Gets value with function value = get_attr_value(instance, attribute_name) # For method attributes --- FIXME: check what does this code here, because # get_attr_value has a code to do that, using # callable() checking if type(value) == types.MethodType: value = value() return value
def get_object_value(self, instance=None, attribute_name=None): """Return the attribute value for just an object""" instance = instance or self.instance attribute_name = attribute_name or self.attribute_name # Checks lambda and instance if self.get_value and instance: try: return self.get_value(self, instance) except TypeError: return self.get_value(instance) # Checks this is an expression tokens = EXP_TOKENS.split(attribute_name) tokens = filter(bool, tokens) # Cleans empty parts if len(tokens) > 1: values = {} for token in tokens: if not token in ('+', '-', '*', '/', '**') and not token.isdigit(): values[token] = self.get_object_value(instance, token) return eval(attribute_name, values) # Gets value with function value = get_attr_value(instance, attribute_name) # For method attributes --- FIXME: check what does this code here, because # get_attr_value has a code to do that, using # callable() checking if type(value) == types.MethodType: value = value() return value
def get_attr_value(self, obj, attr): """Returns the attribute value on an object, and converts decimal to float if necessary.""" value = get_attr_value(obj, attr) if isinstance(value, decimal.Decimal) and self.decimal_as_float: value = float(value) return value
def get_attr_value(self, obj, attr): """Returns the attribute value on an object, and converts decimal to float if necessary.""" value = get_attr_value(obj, attr) if isinstance(value, decimal.Decimal) and self.decimal_as_float: value = float(value) return value
def get_object_value(self, instance=None): """Return the attribute value for just an object""" instance = instance or self.instance if self.get_value and instance: return self.get_value(instance) value = get_attr_value(instance, self.attribute_name) return value
def get_object_value(self, instance=None): """Return the attribute value for just an object""" instance = instance or self.instance if self.get_value and instance: return self.get_value(instance) value = get_attr_value(instance, self.attribute_name) return value
def get_object_value(self, instance=None): """Return the attribute value for just an object""" instance = instance or self.instance if self.get_value and instance: return self.get_value(instance) value = get_attr_value(instance, self.attribute_name) # For method attributes if type(value) == types.MethodType: value = value() return value
def get_object_value(self, instance=None): """Return the attribute value for just an object""" instance = instance or self.instance if self.get_value and instance: return self.get_value(instance) value = get_attr_value(instance, self.attribute_name) # For method attributes if type(value) == types.MethodType: value = value() return value
def make_hash_key(report, objects_list): """This function make a hash key from a list of objects. Situation 1 ----------- If the objects have an method 'repr_for_cache_hash_key', it is called to get their string repr value. This is the default way to get repr strings from rendered pages and objects. Situation 2 ----------- Otherwise, if exists, the method 'get_cache_relevant_attributes' from report will be called to request what attributes have to be used from the object list to make the string. If the method above does't exists, then all attributes explicitly found in report elements will be used. The result list will be transformed to a long concatenated string and a hash key will be generated from it.""" global get_report_cache_attributes result = [] # Get attributes for cache from report if hasattr(report, 'get_cache_relevant_attributes'): report_attrs = report.get_cache_relevant_attributes else: report_attrs = lambda: get_report_cache_attributes(report) for obj in objects_list: # Situation 1 - mostly report pages and geraldo objects if hasattr(obj, 'repr_for_cache_hash_key'): result.append(obj.repr_for_cache_hash_key()) # Situation 2 - mostly queryset objects list else: result.append(u'/'.join([ unicode(get_attr_value(obj, attr)) for attr in report_attrs() ])) # Makes the hash key m = hash_constructor() m.update(u'\n'.join(result)) return '%s-%s' % (report.cache_prefix, m.hexdigest())
def make_hash_key(report, objects_list): """This function make a hash key from a list of objects. Situation 1 ----------- If the objects have an method 'repr_for_cache_hash_key', it is called to get their string repr value. This is the default way to get repr strings from rendered pages and objects. Situation 2 ----------- Otherwise, if exists, the method 'get_cache_relevant_attributes' from report will be called to request what attributes have to be used from the object list to make the string. If the method above does't exists, then all attributes explicitly found in report elements will be used. The result list will be transformed to a long concatenated string and a hash key will be generated from it.""" global get_report_cache_attributes result = [] # Get attributes for cache from report if hasattr(report, 'get_cache_relevant_attributes'): report_attrs = report.get_cache_relevant_attributes else: report_attrs = lambda: get_report_cache_attributes(report) for obj in objects_list: # Situation 1 - mostly report pages and geraldo objects if hasattr(obj, 'repr_for_cache_hash_key'): result.append(obj.repr_for_cache_hash_key()) # Situation 2 - mostly queryset objects list else: result.append(u'/'.join([unicode(get_attr_value(obj, attr)) for attr in report_attrs()])) # Makes the hash key m = hash_constructor() m.update(u'\n'.join(result)) return '%s-%s'%(report.cache_prefix, m.hexdigest())
def render(self): if not getattr(self, "_rendered_drawing", None): kwargs = {"value": self.get_object_value(), "barWidth": self.width, "barHeight": self.height} if self.type in ("EAN13", "EAN8"): self._rendered_drawing = createBarcodeDrawing(self.type, **kwargs) else: cls = BARCODE_CLASSES[self.type] kwargs["checksum"] = self.checksum if self.type in ("USPS_4State",): kwargs["routing"] = get_attr_value(self.instance, self.routing_attribute) self._rendered_drawing = cls(**kwargs) return self._rendered_drawing
def get_object_value(self, instance=None): """Return the attribute value for just an object""" instance = instance or self.instance if self.get_value and instance: try: return self.get_value(self, instance) except TypeError: return self.get_value(instance) value = get_attr_value(instance, self.attribute_name) # For method attributes --- FIXME: check what does this code here, because # get_attr_value has a code to do that, using # callable() checking if type(value) == types.MethodType: value = value() return value
def get_cross_data(self, data=None): if not getattr(self, '_cross_data', None): data = data or self.data # Transforms data to cross-reference matrix if isinstance(data, basestring): data = get_attr_value(self.instance, data) if not isinstance(data, CrossReferenceMatrix): if self.rows_attribute: # and self.cols_attribute: data = CrossReferenceMatrix( data, self.rows_attribute, self.cols_attribute, decimal_as_float=True, ) self._cross_data = data return self._cross_data
def render(self): if not getattr(self, '_rendered_drawing', None): kwargs = { 'value': self.get_object_value(), 'barWidth': self.width, 'barHeight': self.height, } if self.type in ('EAN13','EAN8',): self._rendered_drawing = createBarcodeDrawing(self.type, **kwargs) else: cls = BARCODE_CLASSES[self.type] kwargs['checksum'] = self.checksum if self.type in ('USPS_4State',): kwargs['routing'] = get_attr_value(self.instance, self.routing_attribute) self._rendered_drawing = cls(**kwargs) return self._rendered_drawing