On Apr 29, 1:08 am, Jorge Vargas <[email protected]> wrote:
> could you please post those?

Basically just an Elixir version of the quickstart, the User table has
more things.

class Group(DeclarativeBase):
        """
        Group definition for :mod:`repoze.what`.

        Only the ``group_name`` column is required by :mod:`repoze.what`.
        """

        #{ Columns
        group_id = Field(Integer, autoincrement=True, primary_key=True)
        group_name = Field(Unicode(16), unique=True, nullable=False)
        display_name = Field(Unicode(255))
        created = Field(DateTime, default=datetime.now)

        #{ Relations
        users = ManyToMany('User')
        permissions = ManyToMany('Permission')

        #{ Special methods
        def __repr__(self):
                return '<Group: name=%s>' % self.group_name

        def __unicode__(self):
                return self.group_name

class User(DeclarativeBase):
        """
        User definition.

        This is the user definition used by :mod:`repoze.who`, which requires
at
        least the ``user_name`` column.

        """

        #{ Columns
        user_id = Field(Integer, autoincrement=True, primary_key=True)
        user_name = Field(Unicode(255), unique=True, nullable=False)

        @property
        def email_address(self):
                return self.user_name
        _password = Field(Unicode(80), colname='password', nullable=False)
        created = Field(DateTime, default=datetime.now)

        first_name = Field(Unicode(127))
        last_name = Field(Unicode(127))
        # The rest of this information is very USA-oriented, to add
        # international support may not be the easiest thing...
        address = Field(Unicode(255))
        city = Field(Unicode(127))
        state = Field(String(2))
        zipcode = Field(String(10)) # to support the 5-4 format if necessary
        home_phone = Field(String(32)) # Enough space to hold a number and an
extension if necessary
        cell_phone = Field(String(32)) # Enough space to hold a number and an
extension if necessary
        birth_date = Field(Date)

        #{ Relations
        groups = ManyToMany('Group')

        #{ Special methods
        def __repr__(self):
                return '<User: email="%s", first name="%s", password="%s">' % (
                                self.email_address, self.first_name, 
self.password)

        def __unicode__(self):
                return self.first_name or self.user_name

        #{ Getters and setters

        @property
        def permissions(self):
                """Return a set of strings for the permissions granted."""
                perms = set()
                for g in self.groups:
                        perms = perms | set(g.permissions)
                return perms

        @classmethod
        def by_email_address(cls, email):
                """Return the user object whose email address is ``email``."""
                return 
DBSession.query(cls).filter(cls.email_address==email).first()

        @classmethod
        def by_user_name(cls, username):
                """Return the user object whose user name is ``username``."""
                return 
DBSession.query(cls).filter(cls.user_name==username).first()

        def _set_password(self, password):
                """Hash ``password`` on the fly and store its hashed version."""
                hashed_password = password

                if isinstance(password, unicode):
                        password_8bit = password.encode('UTF-8')
                else:
                        password_8bit = password

                salt = sha1()
                salt.update(os.urandom(60))
                hash = sha1()
                hash.update(password_8bit + salt.hexdigest())
                hashed_password = salt.hexdigest() + hash.hexdigest()

                # Make sure the hashed password is an UTF-8 object at the end 
of the
                # process because SQLAlchemy _wants_ a unicode object for 
Unicode
                # columns
                if not isinstance(hashed_password, unicode):
                        hashed_password = hashed_password.decode('UTF-8')

                self._password = hashed_password

        def _get_password(self):
                """Return the hashed version of the password."""
                return self._password

        #password = synonym('_password', descriptor=property(_get_password,
        #                                                                       
                                _set_password))
        password = property(_get_password, _set_password)

        #}

        def validate_password(self, password):
                """
                Check the password against existing credentials.

                :param password: the password that was provided by the user to
                        try and authenticate. This is the clear text version 
that we will
                        need to match against the hashed one in the database.
                :type password: unicode object.
                :return: Whether the password is valid.
                :rtype: bool

                """
                hashed_pass = sha1()
                hashed_pass.update(password + self.password[:40])
                return self.password[40:] == hashed_pass.hexdigest()

class Permission(DeclarativeBase):
        """
        Permission definition for :mod:`repoze.what`.

        Only the ``permission_name`` column is required
by :mod:`repoze.what`.

        """

        #{ Columns

        permission_id = Field(Integer, autoincrement=True, primary_key=True)
        permission_name = Field(Unicode(16), unique=True, nullable=False)
        description = Field(Unicode(255))

        #{ Relations
        groups = ManyToMany('Group')

        #{ Special methods

        def __repr__(self):
                return '<Permission: name=%s>' % self.permission_name

        def __unicode__(self):
                return self.permission_name

>
> > And yes, I searched this list, found someone mentioning this as a
> > known bug many months ago, but nothing before or since.
>
> link? please remenber tgadmin is very new and it may have some bugs on
> edge cases.

It is setup in the quickstart project though as the line "#admin =
Catwalk(model, DBSession)" in the root controller, all I do is
uncomment it, launch the server, log in, goto the /admin/ link, click
User, click New, and I get:
IntegrityError: (IntegrityError) is420_model_auth_user.user_name may
not be NULL u'INSERT INTO is420_model_auth_user (user_name, password,
created, first_name, last_name, address, city, state, zipcode,
home_phone, cell_phone, birth_date) VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' [None, None, '2009-05-02
02:51:57.522000', None, None, None, None, None, None, None, None,
None]

And the exception occurs during the transaction commit, no where near
the callsite, thus making it very difficult to find...


On Apr 30, 11:13 pm, Iain Duncan <[email protected]> wrote:
> This is a total shot in the dark, but it *could* be an old version of
> toscawidgets. I don't know the AdminController code at all, so I don't
> know if it's doing the same thing as my home-brew one was, but there was
> a period where TW was calling all arguments passed in to widgets at init
> time, so if you passed in a ref to a model class, you would get spurious
> object creation. Alberto fixed that, but maybe try upgrading your
> toscawidgets? Total guess.
>
> That said, it sounds like even if isn't happening that way, you could
> look for places where class refs are getting called by accident. :/

I just tried to force updates on all the packages in the virtual
environment, the only thing that was not all the way up to date (-U
switch for easy_install for each individual package) was formencode
(1.2.2 apparently came out recently), which did not change the error
at all.
--~--~---------~--~----~------------~-------~--~----~
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