Hello,
  Thanks for the response but I have hit another roadblock, sometimes
this can be frustrating.  So I need the id field as well as the name
field to correctly check the integrity since I don't want it to error
out if the entry in the data base is the same as the entry I am trying
to update.
ie.
try:
  obj = Product.byName(name)
except SQLObjectNotFound:
  pass
else:
  if id==obj.id: #THIS CASE RIGHT HERE
    pass
  else:
    raise Invalid(...)

So do I need to make a schema?

And if so... should it be like this:

######IN project.validators######
  class IntegrityValidator(FormValidator):
    ...
    def _to_python(self, value, state):
      return value
    def _from_python(self, value, state):
      return value
    def validate_python(self, value, state):
      id = value['id']
      name = value['name']
      ...do something similar to what I did above to check integrity...


  class IntegritySchema(Schema):
    chained_validators=[IntegrityValidator(...),]

#######IN project.controllers########
  form = widgets.TableForm(...., validator=IntegritySchema())


I am trying something like that and getting this:

    submit_text="Save", action="saveClothingProduct",
validator=IntegritySchema())
  File 
"/usr/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/widgets/meta.py",
line 171, in widget_init
    validator = generate_schema(self.validator, widgets)
  File 
"/usr/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/widgets/meta.py",
line 268, in generate_schema
    schema = copy_schema(schema)
  File 
"/usr/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/widgets/meta.py",
line 213, in copy_schema
    return copy.deepcopy(schema)
  File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.4/copy.py", line 351, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.4/copy.py", line 174, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.4/copy.py", line 268, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.4/copy.py", line 174, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.4/copy.py", line 241, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.4/copy.py", line 351, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.4/copy.py", line 174, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.4/copy.py", line 268, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.4/copy.py", line 174, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.4/copy.py", line 248, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.4/copy.py", line 336, in _reconstruct
    y = callable(*args)
  File "/usr/lib/python2.4/copy_reg.py", line 92, in __newobj__
    return cls.__new__(cls, *args)
TypeError: instancemethod expected at least 2 arguments, got 0

Thanks,
  -Ian

On 8/13/06, Alberto Valverde <[EMAIL PROTECTED]> wrote:
>
>
> On Aug 13, 2006, at 4:17 AM, Ian Wilson wrote:
>
> >
> > Hello,
> >   How can I emulate the error handler without using a validator?  For
> > example if a product's name is a duplicate I need to go back to the
> > form and have name's error text read "A product with this name already
> > exists."
> >
> > So say I have something like this:
> >
> > @expose(...)
> > def edit(self, **kwargs):
> >   return dict(form=form, ...)
> >
> > @expose(...)
> > @validate(form=form)
> > @error_handler(edit)
> > def save(self, **kwargs):
> >   id = kwargs.get('id', None)
> >   name = kwargs.get('name')
> >   #Check if duplicate exists
> >   try:
> >     duplicateProduct = Product.byName(name):
> >   except:
> >     pass
> >   else:
> >     if duplicateProduct.id != id: #Product with same name and
> > different id exists
> >       #Error here for name field, what goes here to get back to edit?
> >       ...
> >
> >   ...
> >
> >   redirect("/edit", id=id)
>
> You could check for the duplicate in a custom validator for the name
> field so you can raise an Invalid exception with the error message. I
> think it would be the easiest way to accomplish what your'e trying to
> do.
>
> Alternatively, you could raise an exception insde the controller and
> catch it with an exception_handler that branches to an exception
> handler method.
>
> HTH,
> Alberto
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to