Django

Code

Changeset 7024

Show
Ignore:
Timestamp:
01/18/08 09:52:37 (8 months ago)
Author:
jbronn
Message:

gis: LayerMapping: Fixed bug that would occur when mapping OFTReal fields with precision > 0 to an IntegerField.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/utils/layermapping.py

    r7013 r7024  
    125125class InvalidString(LayerMapError): pass 
    126126class InvalidDecimal(LayerMapError): pass 
     127class InvalidInteger(LayerMapError): pass 
    127128class MissingForeignKey(LayerMapError): pass 
    128129 
     
    407408                    raise InvalidString('%s model field maximum string length is %s, given %s characters.' % 
    408409                                        (model_field.name, model_field.max_length, len(val))) 
    409         elif isinstance(ogr_field, OFTReal)
     410        elif isinstance(ogr_field, OFTReal) and isinstance(model_field, models.DecimalField)
    410411            try: 
    411412                # Creating an instance of the Decimal value to use. 
    412413                d = Decimal(str(ogr_field.value)) 
    413414            except: 
    414                 raise InvalidDecimal('Could not construct decimal from: %s' % ogr_field
     415                raise InvalidDecimal('Could not construct decimal from: %s' % ogr_field.value
    415416 
    416417            # Getting the decimal value as a tuple. 
     
    435436                                     (model_field.max_digits, model_field.decimal_places, max_prec)) 
    436437            val = d 
     438        elif isinstance(ogr_field, OFTReal) and isinstance(model_field, models.IntegerField): 
     439            # If there's an OFTReal field with precision greater than 0 is mapped to 
     440            # an IntegerField, the decimal places will be truncated. 
     441            try: 
     442                val = int(ogr_field.value) 
     443            except: 
     444                raise InvalidInteger('Could not construct integer from: %s' % ogr_field.value) 
    437445        else: 
    438446            val = ogr_field.value