[Grok-dev] LoginDemo and PlainLoginDemo
sebastian at urbantalk.se
Sun Jan 13 12:31:02 EST 2008
I might be making a fool of myself, and I haven't tested this code,
but I would have thought that by adding the following to your
PlainLoginDemo, you would have easily extendable user objects that
would support automatic form generation etc. (I guess you could
compact it further by removing the interfaces. Then you would go from
49 LOC down to 32 LOC)
In order to access the user objects you write:
userhandler = IUserDatabase(grok.getSite())
user = userhandler.getUser(username)
user.email = 'iam at email.com'
...or whatever you wish to do...
from zope.interface import Interface
from zope import schema
from BTrees.OOBTree import OOTreeSet
from logindemo.app import LoginDemo
This is the edit history annotation.
title = schema.TextLine(title=u"email", required=False)
title = schema.Text(title=u"description", required=False)
This is the user annotation mechanism.
def addUser(username, email, description):
""" Add a user object to the user database. """
""" Get a user object. """
""" Remove a user object. """
def __init__(self, email=None, description=None):
self.email = email
self.description = description
self._users = OOTreeSet() # I should probably use some other
def addUser(self, username, email, description):
# Raise some kind of error?
self._users[username] = User(email, description)
def getUser(self, username):
def delUser(self, username):
13 jan 2008 kl. 16.06 skrev Luciano Ramalho:
> Today I removed everything related to annotations from the LoginDemo
> and created PlainLoginDemo:
> Removing the email field resulted in a reduction of more than 100
> lines of code, because then I did not need to define an interface but
> used the predefined IInternalPrincipal interface; email validation and
> the UserData adapter also became unnecessary.
> I also added docstrings and comments.
> I will continue to work on both LoginDemo and PlainLogin demo over the
> next few days.
> Grok-dev mailing list
> Grok-dev at zope.org
More information about the Grok-dev