The difference is that when the validator runs, it has access to global scope variables (request, response, SQLDB), but it does not have access to my controller local variables (which is where the data I'm trying to validate resides).  Currently, validators only validate based on 1 value passed in or based on what it can access on the global scope.  I'm trying to validate based on something that is in neither in the global scope nor is it the value passed it.  It does, however, have a relationship to the value passed in.  The right way to handle this is to pass in the record being validated and the name of the field to validate to the validator so that the validator can handle inter-data relationships like this.

Does that makes sense?

-tim

mdipierro wrote:
I still do not see why you cannot use IS_NOT_IN_DB(sqlset,....) You
must have access to the variables that you want to validate.

Massimo

On Dec 12, 3:01 pm, Timothy Farrell <tfarr...@swgen.com> wrote:
  
The page in question is sorta like an SQLtable, it displays a full table and allows for updates to each record without branching off to a separate page.  When the user is done making changes the wraps up the changes made and POSTs a JSON object to the web2py controller.
This is a custom built page that uses _javascript_ to wrap up the data and build the JSON object.  Once in the controller, the controller unpacks the JSON object and sends it to through an SQLFORM.accepts() validator (in a loop since there are multiple records).
So you see, the data being validated does not directly come from requests.vars in a form that I can put in a application-wide validator.
-tim
mdipierro wrote:I do not understand. Where is your input from? Massimo On Dec 12, 2:42 pm, Timothy Farrell<tfarr...@swgen.com>wrote:Yes, that would work if I used normal HTML forms (and I think that was what I was looking for previously), but in my case, what would berequest.vars.field1in your example is really something likesimplejson.loads(request.vars.JSONdata)[2]['field1']. And since that changes on a controller level, I can't put it in as a database validator (which I would like to do). I could, of course, code a custom validator for each controller, but that gets around the point of having a DAL that can enforce database integrity. mdipierro wrote:you do not need this because you can already do it. requires=IS_NOT_IN_DB(db (db.table.field1==request.vars.field1),'table.field2') Massimo On Dec 12, 2:20 pm, Timothy Farrell<tfarr.
....@swgen.com>wrote:Yes, this would require changing some things in gluon.validators and gluon.html. I'm of the mindset that this sort of validator is very important. However, I'll have to look into it later. Could you send me your code if you still have it? Thanks, tim DenesL wrote:Oops, I misunderstood your goal. Actually I wrote a ROW_NOT_IN_DB validator which did not get Massimo's approval, but looking back it might have been because I used a bad example to make the case. Anyways, just coding the validator was not enough, I had to modify a few things in gluon too. On Dec 12, 12:19 pm, Timothy Farrell<tfarr...@swgen.com>wrote:Hel p me understand how this works. "value", in the _expression_, gets replaced with the value being validated, correct? If so, then your suggestions check if field1 == field2. That's not quite what I'm looking for. What I'm looking for would be something like this:ARE_NOT
_IN_DB(db, 'table', ['field1', 'field2', 'field3], error_message='ACK!') I think I'll have to code this up real quick. DenesL wrote:You can probably tailor this to your needs: db.mytable.field2.requires=IS_EXPR('value==%s' % repr (request.vars.field1),error_message='oops!') or the equivalent (and more flexible): db.mytable.field2.requires=IS_EXPR('True' ),error_message='oops!') db.mytable.field2.requires.expressions='value==%s' % repr (request.vars.field1)-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)-- Timothy Farrell<tfarr...@swgen.com>Computer Guy Statewide General Insurance Agency (www.swgen.com)
    

  

-- 
Timothy Farrell <tfarr...@swgen.com>
Computer Guy
Statewide General Insurance Agency (www.swgen.com)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to