Thx Anthony ! Il giorno giovedì 18 febbraio 2016 21:22:05 UTC+1, Anthony ha scritto: > > ...... > > > db.poc.Name.requires = [IS_UPPER > <https://xortho.it/examples/global/vars/IS_UPPER>(), CRYPT > <https://xortho.it/examples/global/vars/CRYPT>(), > IS_NOT_IN_DB(db(db.poc.Birthday == > request.vars.Birthday), 'poc.Name')] > > > I've tried but this doesn't work properly and adds duplicated data. I figured out that is probably because I'm using CRYPT() and I get a LazyCrypt Object but IS_NOT_IN_DB expects a string
Where can'I find the source code for _before_insert? > A few additional tips: > > > - form.process() accepts a "message_onsuccess" argument, so you can > use that instead of checking if the form is accepted and explicitly > setting > response.flash. > > Tried and this prevent "record added" message but I'm still unable to show a duplicate error message. > - If your callback function already has the proper signature (i.e., > accepts the arguments that will be passed when called), there is no need > to > wrap it in a lambda. Just do > db.poc._before_insert.append(controlla_record). > > Good > > - If you want to determine whether a given value exists in a > particular database field, you should not loop through all the records in > Python but instead simply let the database do the work: > > if not db((db.poc.Birthday == dati.get("Birthday")) & > (db.poc.Name == CRYPT()(request.vars.get('Name', > '').upper())[0])).isempty(): > return 'error' > > Got it ... > > > > - If you are going to loop through a set of records, don't recalculate > the same value over and over inside the loop (i.e., in your callback, you > would move the transformation of the Name via CRYPT outside the loop, as > you only need to do it once). > > Correct ! > Anthony > > On Thursday, February 18, 2016 at 12:13:55 PM UTC-5, Ivan Gazzola wrote: >> >> ### Controller for poc form >> >> >> def insert_poc(): >> form=SQLFORM(db.poc) >> if form.process().accepted: >> response.flash = T('Record added') >> return dict(form=form) >> >> >> I've posted the full model, the function is colled in _before_insert: >> >> db.poc._before_insert.append(lambda dati: controlla_record(dati)) >> >> >> Il giorno giovedì 18 febbraio 2016 17:28:15 UTC+1, Anthony ha scritto: >> >> We need to see the full code, including the controller. In particular, >> you show a callback function, but you do not show where it is called. >> >> Anthony >> >> On Thursday, February 18, 2016 at 8:55:49 AM UTC-5, Ivan Gazzola wrote: >> >> >> db.define_table('poc', >> Field >> <https://xortho.it/examples/global/vars/Field>('Name',required=True), >> Field >> <https://xortho.it/examples/global/vars/Field>('Birthday','date',widget=bsdatepicker_widget(),required=True), >> Field >> <https://xortho.it/examples/global/vars/Field>('Angle_Class_Dx',label=T >> <https://xortho.it/examples/global/vars/T>("Angle's Class Dx")), >> Field >> <https://xortho.it/examples/global/vars/Field>('Angle_Class_Sn',label=T >> <https://xortho.it/examples/global/vars/T>("Angle's Class Sn")), >> Field >> <https://xortho.it/examples/global/vars/Field>('Facial_Type'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Overjet'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Overbite'), >> Field <https://xortho.it/examples/global/vars/Field>('Sex'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Ratial'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Cot1','upload',required=True), >> Field >> <https://xortho.it/examples/global/vars/Field>('Cot2','upload'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Cot3','upload'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Clench','upload',required=True), >> Field >> <https://xortho.it/examples/global/vars/Field>('Chewing_dx','upload',required=True), >> Field >> <https://xortho.it/examples/global/vars/Field>('Chewing_sn','upload',required=True), >> Field >> <https://xortho.it/examples/global/vars/Field>('Lateral_Ceph','upload'), >> Field >> <https://xortho.it/examples/global/vars/Field>('Dental_Formula','text'), >> auth.signature >> ) >> >> >> >> def controlla_record(dati): >> nascite=db(db.poc.Birthday==dati.get("Birthday")).select() >> for soggetto in nascite: >> if CRYPT <https://xortho.it/examples/global/vars/CRYPT>()(request >> <https://xortho.it/examples/global/vars/request>.vars.get("Name",'').upper())[0]==soggetto.Name: >> response.flash=T("Duplicate Records Not Allowed") >> return "errore" >> >> >> db.poc.Angle_Class_Dx.requires = IS_IN_SET >> <https://xortho.it/examples/global/vars/IS_IN_SET>([('1','I'),('2','II'),('3','III')]) >> db.poc.Angle_Class_Sn.requires = IS_IN_SET >> <https://xortho.it/examples/global/vars/IS_IN_SET>([('1','I'),('2','II'),('3','III')]) >> db.poc.Facial_Type.requires=IS_IN_SET >> <https://xortho.it/examples/global/vars/IS_IN_SET>({'N':'Normo','O':'Open','D':'Deep'}) >> db.poc.Overjet.requires=IS_IN_SET >> <https://xortho.it/examples/global/vars/IS_IN_SET>([('1','OJ < >> 2mm'),('2','2mm < OJ < 4mm'),('3','OJ > 4mm')]) >> db.poc.Overbite.requires=IS_IN_SET >> <https://xortho.it/examples/global/vars/IS_IN_SET>([('1','OB < >> 2mm'),('2','2mm < OB < 4mm'),('3','OB > 4mm')]) >> db.poc.Sex.requires= <https://xortho.it/examples/global/vars/IS_IN_SET> >> >> ... > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.