コード例 #1
0
ファイル: barcodes.py プロジェクト: Willix0801/django_intouch
    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
コード例 #2
0
ファイル: widgets.py プロジェクト: raminel/geraldo
    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
コード例 #3
0
ファイル: widgets.py プロジェクト: robjohnson189/geraldo
    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
コード例 #4
0
ファイル: cross_reference.py プロジェクト: Guillon88/stdm
    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
コード例 #5
0
    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
コード例 #6
0
    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
コード例 #7
0
ファイル: barcodes.py プロジェクト: Willix0801/django_intouch
    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
コード例 #8
0
ファイル: widgets.py プロジェクト: gustavohenrique/wms
    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
コード例 #9
0
ファイル: widgets.py プロジェクト: jjesquea/wms
    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
コード例 #10
0
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())
コード例 #11
0
ファイル: cache.py プロジェクト: Guillon88/stdm
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())
コード例 #12
0
    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
コード例 #13
0
ファイル: widgets.py プロジェクト: timesong/geraldo
    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
コード例 #14
0
    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
コード例 #15
0
ファイル: barcodes.py プロジェクト: aregee/network-admin
    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