I would recomend not to touch default auth tables "tg_" (their names in __tablename__ ), wich are made by quickstart. Add needed fields and new tables with relations on these tables. Base on model, shown by Christoph. New tables will be Project and Association.
if You change someting in model, you shold make "setup-app" again. It is better first to rename Your devdata.db if it has something useful, or delete if not. Step 1: Make new project using quickstart. Step 2: Edit model/auth.py (add new fields and Classes only! Do not rename __tablename__ property in default classes) Step 3: Add new Classes into "import" string inside file model/__init__.py Step 4: Setup Your project using "paster setup-app development.ini". Step 5: ??????? Step 6: Profit 2011/2/18 Abdul Gaffar <[email protected]> > Hi all, > > > If anybody can give the complete example of User, Group, permission, > Project table with the association table, that should work with repoze > authentication and authorization framework. > > > User table sholud contain > --------------- > user_id, > user_name, > email_address > > > Group table should contain > -------------------------- > group_id > group_name > > > Permission > ---------- > permission_id > permission_name > > > > Project_table > ------------- > project_id > project_name > > > > > and the association table should contain > ---------------------------------------- > user_id > group_id > project_id > > > -------------------------------------------------------- > :) :) > Abdul Gaffar > > -------------------------------- > > On Fri, 2011-02-18 at 10:41 +0100, Luca Verardi wrote: > > mmm.. I'm not sure but.. > > Have you to specify a relation like this? in Class Association > > group = relationship('Group', primaryjoin=group_id==Group.group_id > ,backref='associations',cascade="all, delete") > > > > > > > > > > On 02/18/2011 08:53 AM, Abdul Gaffar wrote: > > > Hi, > > > > > > I tried the following example, rows are inserting fine but when I try > > > to login I am getting the following error. > > > > > > > > > > > > > > > > > > Error -<class 'sqlalchemy.exc.InvalidRequestError'>: Mapper 'Mapper| > > > User|t_user' has no property 'groups' > > > URL: http://192.168.2.129:8081/login_handler?__logins=0&came_from=%2F > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/WebError-0.10.1-py2.6.egg/weberror/errormiddleware.py', > line 162 in __call__ > > > app_iter = self.application(environ, sr_checker) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/TurboGears2-2.1-py2.6.egg/tg/configuration.py', > line 796 in remover > > > return app(environ, start_response) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.tm2-1.0b1-py2.6.egg/repoze/tm/__init__.py', > line 23 in __call__ > > > result = self.application(environ, save_status_and_headers) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.who-1.0.18-py2.6.egg/repoze/who/middleware.py', > line 85 in __call__ > > > self.add_metadata(environ, classification, identity) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.who-1.0.18-py2.6.egg/repoze/who/middleware.py', > line 179 in add_metadata > > > plugin.add_metadata(environ, identity) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.what-1.0.9-py2.6.egg/repoze/what/middleware.py', > line 98 in add_metadata > > > groups, permissions = self._find_groups(identity) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.what-1.0.9-py2.6.egg/repoze/what/middleware.py', > line 78 in _find_groups > > > groups |= set(grp_fetcher.find_sections(credentials)) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.what-1.0.9-py2.6.egg/repoze/what/adapters/__init__.py', > line 170 in find_sections > > > return self._find_sections(hint) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.what.plugins.sql-1.0-py2.6.egg/repoze/what/plugins/sql/adapters.py', > line 307 in _find_sections > > > user = self._get_item_as_row(id_) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/repoze.what.plugins.sql-1.0-py2.6.egg/repoze/what/plugins/sql/adapters.py', > line 197 in _get_item_as_row > > > query = > > > > self.dbsession.query(self.children_class).options(eagerload(self.translations['sections'])) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', > line 853 in options > > > return self._options(False, *args) > > > File '<string>', line 1 in<lambda> > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', > line 52 in generate > > > fn(self, *args[1:], **kw) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', > line 870 in _options > > > opt.process_query(self) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/interfaces.py', > line 760 in process_query > > > self._process(query, True) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/interfaces.py', > line 766 in _process > > > paths, mappers = self._get_paths(query, raiseerr) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/interfaces.py', > line 843 in _get_paths > > > resolve_synonyms=True, raiseerr=raiseerr) > > > File > > > > '/home/gaffar/ProjectWork/tg2env/lib/python2.6/site-packages/SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', > line 941 in get_property > > > "Mapper '%s' has no property '%s'" % (self, key)) > > > InvalidRequestError: Mapper 'Mapper|User|t_user' has no property > > > 'groups' > > > > > > > > > ------------------------------------ > > > > > > > > > > > > > > > On Thu, 2011-02-17 at 14:02 +0100, Christoph Zwerschke wrote: > > > > > >> Am 17.02.2011 13:00 schrieb Abdul Gaffar: > > >> > > >>> I tried this example, I am facing proble while inserting the > records.. > > >>> > > >> I think the problem is you can't easily associate items with > SQLAlchemy > > >> by using the relationship property. It's really made only for binary > > >> relationships. I guess you need to do it explicitely, like this: > > >> > > >> user = User.query.filter_by(user_name='abdul').one() > > >> group = Group.query.filter_by(group_name='foo').one() > > >> project = Project.query.filter_by(project_name='tg').one() > > >> > > >> DBSession.add(Association(user, group, project)) > > >> > > >> DBSession.flush() > > >> > > >> print user.groups_for_project(project) > > >> > > >> where the classes are defined like that: > > >> > > >> > > >> class Association(DeclarativeBase): > > >> __tablename__ = 't_assoc' > > >> > > >> user_id = Column(Integer, ForeignKey('t_user.user_id', > > >> onupdate="CASCADE", ondelete="CASCADE"), primary_key=True) > > >> group_id = Column(Integer, ForeignKey('t_group.group_id', > > >> onupdate="CASCADE", ondelete="CASCADE"), primary_key=True,) > > >> project_id = Column(Integer, ForeignKey('t_project.project_id', > > >> onupdate="CASCADE", ondelete="CASCADE"), primary_key=True) > > >> > > >> user = relationship('User', backref='associations', > > >> cascade="all, delete") > > >> group = relationship('Group', backref='associations', > > >> cascade="all, delete") > > >> project = relationship('Project', backref='associations', > > >> cascade="all, delete") > > >> > > >> def __init__(self, user, group, project): > > >> self.user_id = user.user_id > > >> self.group_id = group.group_id > > >> self.project_id = project.project_id > > >> > > >> > > >> class User(DeclarativeBase): > > >> __tablename__ = 't_user' > > >> > > >> user_id = Column(Integer, autoincrement=True, primary_key=True) > > >> user_name = Column(Unicode(32), unique=True, nullable=False) > > >> email_address = Column(Unicode(320), unique=True, > nullable=False, > > >> info={'rum': {'field':'Email'}}) > > >> > > >> def __repr__(self): > > >> return ('<User: user_name=%r, email=%r>' % ( > > >> self.user_name, self.email_address)) > > >> > > >> def __unicode__(self): > > >> return self.user_name > > >> > > >> def groups_for_project(self, project): > > >> return Project.query.join(Association).filter_by( > > >> project_id=project.project_id, > user_id=self.user_id).all() > > >> > > >> > > >> class Group(DeclarativeBase): > > >> __tablename__ = 't_group' > > >> > > >> group_id = Column(Integer, autoincrement=True, primary_key=True) > > >> group_name = Column(Unicode(16), unique=True) > > >> > > >> def __repr__(self): > > >> return '<Group: name=%r>' % self.group_name > > >> > > >> def __unicode__(self): > > >> return self.group_name > > >> > > >> > > >> class Project(DeclarativeBase): > > >> __tablename__ = 't_project' > > >> > > >> project_id = Column(Integer, autoincrement=True, > primary_key=True) > > >> project_name = Column(Unicode(80), unique=True, nullable=False) > > >> > > >> def __repr__(self): > > >> return '<Project(%r)>' % self.project_name > > >> > > >> > > >> Similarly, you can define User.projects_for_group and the > corresponding > > >> methods on the other classes. > > >> > > >> But you'll probably get a more profound answer on the SA mailing list > > >> (if you follow http://www.gerv.net/hacking/how-to-ask-good-questions/ > ). > > >> > > >> -- Christoph > > >> > > >> > > > > > > > -- > 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. > > -- 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.

