Thanks Massimo! Forgive me my ignorance but I thought that the data definition (including validators) in the model layer is the default way the framework defines and validates the data before sending it to the associated database. Like the model defines data + data validators while forms and other framework parts which talk to the data/model side inherit those definitions and validators. Whats the rational why for instance the framework function for csv import bypasses/ ignores the data validators of the model?
If that behaviour would be a non-default option of import_from_csv_file then it would look more compelling to me. Maybe I'm missing something here? Thanks, Hans On Mar 25, 8:59 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > Thanks for the code you posted. Yes, something like this should be > included in web2py. Let me give it some more thought. > > Validators are not applied by import_from_csv_file because the CSV > format is not the same as the forms. > > Massimo > > On Mar 25, 2:44 pm, johann.scheibelho...@easytouch-edv.com wrote: > > > Massimo, > > > thanks to your code example I managed to get this somehow into the > > model side of things. Reason is because for later maintenance I think > > that multi column unique keys should be set/managed on database/model > > layer. > > > 1) I had to 'exclude' the checking of the current record - hence only > > checking all other records in that table for duplicates (=uniqueness) > > - in oder to get update forms working. Without that the update form > > would always throw the 'already in database' error message = update > > function lost. Can you confirm if that is a good solution without > > negative side effects? > > > 2) csv imports do not apply these validator. how could that be fixed > > best? > > > 3) can this multi column key solution - once its fully working - be > > integrated into future versions of web2py in order that the workaround > > construct could be replaced by something like the 1st line of > > commented code below? > > > #db.shapecolormonth.colorname.requires=[IS_IN_DB(db,'colorname.id','% > > (name)s'),IS_NOT_IN_DB(db > > ((db.shapecolormonth.shapename==request.vars.shapename)& > > (db.shapecolormonth.month==request.vars.month)),db.shapecolormonth.colorname)] > > > # vvvvvvvvvvvvvvvvvvvvvvv workaround construct begins here > > vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv > > # +) the following construct replaces the broken dropdown function of > > the previous commented line of code > > # 1) had to add '&(db.shapecolormonth.id!=request.vars.id)' into the > > IS_NOT_IN_DB parameters in order to get update froms accepting > > # 2) remaining issue: csv import does not apply this validator! > > > class MY_ODD_VALIDATOR(IS_IN_DB): > > def __init__(self,*a,**b): IS_IN_DB.__init__(self,*a,**b) > > def __call__(self,value): > > e=IS_IN_DB.__call__(self,value) > > if e[1]: return e > > e=IS_NOT_IN_DB(db > > ((db.shapecolormonth.shapename==request.vars.shapename)& > > (db.shapecolormonth.month==request.vars.month)&(db.shapecolormonth.id! > > =request.vars.id)),db.shapecolormonth.colorname)(value) > > return e > > > db.shapecolormonth.colorname.requires=MY_ODD_VALIDATOR > > (db,'colorname.id','%(name)s') > > # ^^^^^^^^^^^^ end of workaround construct > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > --Hans > > > On Mar 25, 2:56 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > My suggestion is use the validators for the drop box only, define > > > > def my_check(form): > > > if db( (db.shapecolormonth.shapename==form.vars.shapename) & > > > (db.shapecolormonth.shapecolor==form.vars.shapecolor) & > > > (db.shapecolormonth.month==form.vars.month) ).count(): > > > form.errors.month='sorry, shape+color+month combo have to be > > > unique' > > > return > > > > then in SQLFORM set > > > > SQLFORM(....,onvalidation=my_check) > > > > This is not the only solution. You could do everything with > > > validators, but this solution is simpler. > > > > Massimo --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---