I gave a look at .regexp()... I not really works even if I do something 
like this :

import string
strip_characters = string.punctuation + ' '


The following don't work because the pattern is not found as the database 
entries are not altered before the check :

db(db.auth_user.first_name.regexp(value.translate(None, 
strip_characters))).select()

This don't seems to be supported :

db("translate(auth_user.first_name, '{chars}', '') = 
'{val}'".format(chars=strip_characters, val=value.translate(None, 
strip_characters))).select(db.auth_user.ALL)


I don't see any other choice but add support at adapter level for translate 
function which is not widely supported (SQLite doesn't seems to have such 
function out of the box 
http://stackoverflow.com/questions/13958210/sqlite-function-that-works-like-the-oracles-translate-function)...
 


This would introduce a feature that we couldn't keep undocumented as it 
will not work for all backend...

Are you taking it? Or should I just create my own custom validator and 
unefficiently iterate over record from python and user str.translate() over 
both record input value and new form record value...

Consider that str.translate() as to be treated differently as it not works 
the same between python 2.7 and 3+ (single paramters accepted)

Ref: 
http://stackoverflow.com/questions/34293875/how-to-remove-punctuation-marks-from-a-string-in-python-3-x-using-translate

Python 3 would look like that :

import string
translator = str.maketrans('', '', string.punctuation)
'test(),./'.translate(translator)

VS

Python 2.7 would look like this :

import string
strip_chars = string.punctuation
'test(),./'.translate(None, strip_chars)


What do you think?

Richard






Le mercredi 25 janvier 2017 17:05:18 UTC-5, Richard a écrit :
>
> Hello,
>
> I would do such a thing :
>
> import string
> db(db.ref_method.method_identifier.translate(None, string.punctuation) == 
> test.translate(None, string.punctuation)).select()
>
> But it not work... Would it requires the DAL translate "translate" into 
> sql translate function to achieve that?
>
> I would like to implement into IS_NOT_IN_DB() a "bare" unique constraint 
> that would strip all specials charaters (and space) before make search in 
> the records values to be unique.
>
> Would it works better with regexp??
>
> Thanks
>
> Richard
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to