Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #940 (closed defect: invalid)

Opened 13 years ago

Last modified 12 years ago

upgraded to 0.9a6 and now I'm getting AttributeError: 'int' object has no attribute 'replace'

Reported by: S Brown <trac.turbogears@…> Owned by: anonymous
Priority: normal Milestone:
Component: TurboGears Version: 0.9a6
Severity: normal Keywords: int replace validator
Cc:

Description

Partial trace:

File "/home/sjbrown/ezide/ezide/utils.py", line 37, in KWArgsToAcceptedFailedAndErrors

acceptedVals = schema.to_python( kwargs )

File "/usr/lib/python2.4/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/api.py", line 316, in to_python

value = tp(value, state)

File "/usr/lib/python2.4/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/schema.py", line 132, in _to_python

new[name] = validator.to_python(value, state)

File "/usr/lib/python2.4/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/api.py", line 316, in to_python

value = tp(value, state)

File "/usr/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/validators.py", line 58, in _to_python

value = format.parse_decimal(value)

File "/usr/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/i18n/format.py", line 165, in parse_decimal

value = value.replace(get_group_format(locale), "")

AttributeError?: 'int' object has no attribute 'replace'

Here's the schema I was using:

class SearchSchema(formencode.schema.Schema):
        ignore_key_missing=True
        allow_extra_fields=True
        filter_extra_fields=True #to make a clean querystring in the DB

        allOrOne = validators.OneOf( ['all', 'one'], not_empty=True )
        search_mode = validators.OneOf( ['simple', 'power'], not_empty=True )

        street = validators.PlainText(strip=True,not_empty=False)
        city = validators.PlainText(max=64,strip=True,not_empty=False)
        province = validators.PlainText(max=64,strip=True,not_empty=False)
        country = validators.PlainText(max=64,strip=True,not_empty=False)

        maxPrice = validators.Number(not_empty=False)
        minPrice = validators.Number(not_empty=False)

        startdate = MyDateValidator()
        enddate = MyDateValidator(not_empty=False)

        buildingtype = validators.OneOf( ezidetypes.building.allKeys()+[''] )

        unittype       = validators.OneOf( ezidetypes.unit.allKeys()+[''] )
        parkingtype    = validators.OneOf( ezidetypes.parking.allKeys()+[''] )
        furnishingtype = validators.OneOf( ezidetypes.furnishing.allKeys()+[''])
        laundrytype    = validators.OneOf( ezidetypes.laundry.allKeys()+[''] )
        smokingtype    = validators.OneOf( ezidetypes.smoking.allKeys()+[''] )
        petstype       = validators.OneOf( ezidetypes.pets.allKeys()+[''] )
        handicaptype   = validators.OneOf( ezidetypes.handicap.allKeys()+[''] )

        util_heat = validators.Number(strip=True,not_empty=False)
        util_electricity = validators.Number(strip=True,not_empty=False)
        util_water = validators.Number(strip=True,not_empty=False)
        util_phone = validators.Number(strip=True,not_empty=False)
        util_internet_connection = validators.Number(strip=True,not_empty=False)

        minVacancies = validators.Number(not_empty=False)

        start = validators.Number(not_empty=False, if_empty=1)
        size = BoundedInt( min=25, max=150, if_empty=50 )

My custom validators are here:

class BoundedInt(validators.Int):
        min=1
        max=10
        def validate_python(self, value, state):
                iValidator = validators.Int()
                value = iValidator.to_python( value )

                if value < self.min:
                        msg="Must be at least "+ str(self.min)
                        raise validators.Invalid( msg=msg,
                                                  value=value,
                                                  state=state)
                if value > self.max:
                        msg="The maximum allowed is "+ str(self.max)
                        raise validators.Invalid( msg=msg,
                                                  value=value,
                                                  state=state)

dateConverter = validators.DateConverter(month_style="dd/mm/yyyy")
DATE_FORMAT = "%d/%m/%Y"

class MyDateValidator(validators.DateValidator):
        def _to_python(self, value, state=None):
                if (not self.not_empty) and (value == '' or value == None):
                        return None
                try:
                        value = dateConverter.to_python(value)
                except validators.Invalid, e:
                        print 'date convert error with', value, e
                        raise e
                validator = validators.DateValidator( today_or_after=True,
                                                      not_empty=True )
                dateObj = validator.to_python(value)

                return dateObj.strftime(DATE_FORMAT)

Change History

comment:1 Changed 13 years ago by max

  • Status changed from new to closed
  • Resolution set to invalid

I do not see that TG could be blamed for this; please use TG mailing list to ask for help.

Note: See TracTickets for help on using tickets.