From bd306389f0cac1668691850a09963d3d7ddc9a19 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Mon, 12 Feb 2007 21:39:14 +0000 Subject: [PATCH] - move table description to tables.py - new sysuser class git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@220 a67ec6bc-e5d5-0310-a910-815c51eb3124 --- gnuviechadmin/client.py | 24 ++++------------- gnuviechadmin/sysuser.py | 34 ++++++++++++++++++++++++ gnuviechadmin/tables.py | 57 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 gnuviechadmin/sysuser.py create mode 100644 gnuviechadmin/tables.py diff --git a/gnuviechadmin/client.py b/gnuviechadmin/client.py index 153a14b..561e628 100644 --- a/gnuviechadmin/client.py +++ b/gnuviechadmin/client.py @@ -20,26 +20,10 @@ # Version: $Id$ from sqlalchemy import * -from gnuviechadmin import gva_cfg +from gnuviechadmin.tables import * +from gnuviechadmin import sysuser from gnuviechadmin.exceptions import * -meta = BoundMetaData(gva_cfg.GVA_DBE) -client_table = Table('clients', meta, - Column('clientid', Integer, primary_key=True), - Column('title', String(10)), - Column('firstname', String(64), nullable=False), - Column('lastname', String(64), nullable=False), - Column('address1', String(64), nullable=False), - Column('address2', String(64)), - Column('zip', String(7), nullable=False), - Column('city', String(64), nullable=False), - Column('country', String(5), nullable=False), - Column('phone', String(32), nullable=False), - Column('mobile', String(32)), - Column('fax', String(32)), - Column('email', String(64), unique=True, nullable=False)) -client_table.create(checkfirst=True) - class Client(object): mandatory = ('firstname', 'lastname', 'address1', 'zip', 'city', 'country', 'phone', 'email') @@ -92,7 +76,9 @@ class Client(object): {'clientid' : self.clientid, 'firstname' : self.firstname, 'lastname' : self.lastname, 'email' : self.email}) -clientmapper = mapper(Client, client_table) +clientmapper = mapper( + Client, client_table, + properties = {'sysusers': relation(sysuser.Sysuser)}) def create(**kwargs): try: diff --git a/gnuviechadmin/sysuser.py b/gnuviechadmin/sysuser.py new file mode 100644 index 0000000..4714217 --- /dev/null +++ b/gnuviechadmin/sysuser.py @@ -0,0 +1,34 @@ +# -*- coding: UTF-8 -*- +# +# Copyright (C) 2007 by Jan Dittberner. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. +# +# Version: $Id$ + +from sqlalchemy import * +from gnuviechadmin.tables import * +from gnuviechadmin.exceptions import * + +class Sysuser(object): + def __repr__(self): + return "%(sysuserid)d,%(username)s,%(clientid)d,%(sysuid)d" % ({ + 'sysuserid': self.sysuserid, + 'username': self.username, + 'clientid': self.clientid, + 'sysuid': self.sysuid}) + +sysusermapper = mapper(Sysuser, sysuser_table) diff --git a/gnuviechadmin/tables.py b/gnuviechadmin/tables.py new file mode 100644 index 0000000..7c26e9b --- /dev/null +++ b/gnuviechadmin/tables.py @@ -0,0 +1,57 @@ +# -*- coding: UTF-8 -*- +# +# Copyright (C) 2007 by Jan Dittberner. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. +# +# Version: $Id$ + +from sqlalchemy import * +from gnuviechadmin import gva_cfg + +meta = BoundMetaData(gva_cfg.GVA_DBE) +client_table = Table( + 'client', meta, + Column('clientid', Integer, primary_key=True), + Column('title', String(10)), + Column('firstname', String(64), nullable=False), + Column('lastname', String(64), nullable=False), + Column('address1', String(64), nullable=False), + Column('address2', String(64)), + Column('zip', String(7), nullable=False), + Column('city', String(64), nullable=False), + Column('country', String(5), nullable=False), + Column('phone', String(32), nullable=False), + Column('mobile', String(32)), + Column('fax', String(32)), + Column('email', String(64), unique=True, nullable=False)) +client_table.create(checkfirst=True) + +sysuser_table = Table( + 'sysuser', meta, + Column('sysuserid', Integer, primary_key=True), + Column('username', String(12), nullable=False, unique=True), + Column('usertype', Integer, nullable=False, default=0, index=True), + Column('home', String(128)), + Column('shell', Boolean, nullable=False, default=False), + Column('clearpass', String(64)), + Column('md5pass', String(32)), + Column('clientid', Integer, ForeignKey("client.clientid"), nullable=False), + Column('sysuid', Integer, nullable=False, unique=True), + Column('lastchange', DateTime, default=func.now()) + ) +sysuser_table.create(checkfirst=True) +