Hi all,

I'm facing the following problem and getting nowhere:

During registration I use validators along the lines of (user_name
being one of the alternate keys of the user table)

----------------------------------------------------------------
from model import User
from turbogears.validators import UnicodeString, Invalid

class UsernameValidator(UnicodeString):
    def validate_python(self, username, state=None):
        if not username:
            raise Invalid("No username given", "", state)
        try:
            User.by_user_name(username)
            raise Invalid("The username provided already exists",
username, state)
        except LookupError:
            pass
----------------------------------------------------------------

I've got one of those validators for each alternate key column. For
simplicity's sake think of two validators - one for the user_name one
for the email.

Now think of a "Edit user profile" page with which I'd like to enable
my users to change their unique attributes after registration. So I've
still got to validate that the new value(s) given is still unique. If
a user changes only their email-adress, the validation of the
user_name will fail and vice-versa.
So I'd like to add an option to my validators, which will make them
ignore the current user, something like

----------------------------------------------------------------
from model import User
from turbogears.validators import UnicodeString, Invalid

class UsernameValidator(UnicodeString):
    def validate_python(self, username, state=None):
        if not username:
            raise Invalid("No username given", "", state)
        try:
            ################## here's the not-working change
            user = User.by_user_name(username)
            ################## how do get the needed user id into this
method????
            if user.id !=
the_id_of_the_user_currently_updating_the_userprofile:
                raise Invalid("The username provided already exists",
username, state)
        except LookupError:
            pass
----------------------------------------------------------------

Any suggestions?
BTW, this might very well not be the way to go - so if I'm missing
something, I'd be happy if you could give me a heads-up.

HTH
   Puck


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to