1
0
Fork 0
gnuviechadmin-historic/gnuviechadmin/backend/BackendTo.py

67 lines
2.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008, 2009 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.orm import object_mapper
class BackendTo(object):
"""Backend transfer object class."""
def __init__(self, config, **kwargs):
cols = object_mapper(self).local_table.columns.keys()
for (key, value) in kwargs.items():
if key in cols and value is not None:
self.__setattr__(key, unicode(value, 'utf8'))
def __repr__(self, **kwargs):
if 'verbose' in kwargs and kwargs['verbose']:
cols = object_mapper(self).local_table.columns.keys()
format = "%(class)s:"
format = format + ", ".join([col + "=%(" + col + ")s" for col in \
cols])
data = {'class': self.__class__.__name__}
else:
cols = self._shortkeys
format = ",".join("%(" + col + ")s" for col in cols)
data = {}
data.update(dict([(col, self.__getattribute__(col)) for col in cols]))
return format % data
class Client(BackendTo):
"""Transfer object class for clients."""
_shortkeys = ('clientid', 'firstname', 'lastname', 'email')
class Sysuser(BackendTo):
"""Transfer object class for system users."""
_shortkeys = ("sysuserid", "clientid", "username", "home", "shell")
class Domain(BackendTo):
"""Transfer object class for DNS domains."""
_shortkeys = ("domainid", "sysuserid", "name", "type")
class Record(BackendTo):
"""Transfer object class for DNS domain records."""
_shortkeys = ("recordid", "domainid", "name", "type", "content")