1
0
Fork 0

use explicit unicode columns for client table (fixes #38)

* data/dbrepo/versions/002.py:
  - replace String with Unicode for appropriate columns
 * gnuviechadmin/backend/BackendTo.py:
  - only convert strings to unicode for Unicode columns
 * gnuviechadmin/backend/tables.py:
  - override table definition for client table's Unicode columns
This commit is contained in:
Jan Dittberner 2009-08-02 21:09:07 +02:00
parent d4ba46a329
commit ccaa207d36
3 changed files with 24 additions and 11 deletions

View file

@ -10,13 +10,13 @@ meta = MetaData(migrate_engine)
client = Table( client = Table(
'client', meta, 'client', meta,
Column('clientid', Integer, primary_key=True), Column('clientid', Integer, primary_key=True),
Column('title', String(10)), Column('title', Unicode(10)),
Column('firstname', String(64), nullable=False), Column('firstname', Unicode(64), nullable=False),
Column('lastname', String(64), nullable=False), Column('lastname', Unicode(64), nullable=False),
Column('address1', String(64), nullable=False), Column('address1', Unicode(64), nullable=False),
Column('address2', String(64)), Column('address2', Unicode(64)),
Column('zip', String(7), nullable=False), Column('zip', String(7), nullable=False),
Column('city', String(64), nullable=False), Column('city', Unicode(64), nullable=False),
Column('country', String(5), nullable=False), Column('country', String(5), nullable=False),
Column('phone', String(32), nullable=False), Column('phone', String(32), nullable=False),
Column('mobile', String(32)), Column('mobile', String(32)),

View file

@ -20,16 +20,20 @@
# Version: $Id$ # Version: $Id$
from sqlalchemy.orm import object_mapper from sqlalchemy.orm import object_mapper
from sqlalchemy import Unicode
class BackendTo(object): class BackendTo(object):
"""Backend transfer object class.""" """Backend transfer object class."""
def __init__(self, config, **kwargs): def __init__(self, config, **kwargs):
cols = object_mapper(self).local_table.columns.keys() cols = object_mapper(self).local_table.columns
for (key, value) in kwargs.items(): for (key, value) in kwargs.items():
if key in cols and value is not None: if key in cols.keys() and value is not None:
self.__setattr__(key, unicode(value, 'utf8')) if isinstance(cols[key].type, Unicode):
self.__setattr__(key, value.decode('utf8'))
else:
self.__setattr__(key, value)
def __repr__(self, **kwargs): def __repr__(self, **kwargs):
if 'verbose' in kwargs and kwargs['verbose']: if 'verbose' in kwargs and kwargs['verbose']:

View file

@ -73,13 +73,22 @@ Trying automatic versioning.""")
'organization', meta, 'organization', meta,
Column('name', Unicode(200)), Column('name', Unicode(200)),
schema = dbschema, autoload = True) schema = dbschema, autoload = True)
client_table = Table(
'client', meta,
Column('title', Unicode(10)),
Column('firstname', Unicode(64)),
Column('lastname', Unicode(64)),
Column('address1', Unicode(64)),
Column('address2', Unicode(64)),
Column('city', Unicode(64)),
schema = dbschema, autoload = True)
(client_table, sysuser_table, domain_table, \ (sysuser_table, domain_table, \
record_table, supermaster_table, mailaccount_table, \ record_table, supermaster_table, mailaccount_table, \
mailaddress_table, mailtarget_table) = \ mailaddress_table, mailtarget_table) = \
[Table(tabname, meta, schema = dbschema, [Table(tabname, meta, schema = dbschema,
autoload = True) for tabname in \ autoload = True) for tabname in \
('client', 'sysuser', 'domain', 'record', ('sysuser', 'domain', 'record',
'supermaster', 'mailaccount', 'mailaddress', 'mailtarget')] 'supermaster', 'mailaccount', 'mailaddress', 'mailtarget')]
client_mapper = mapper(Client, client_table, { client_mapper = mapper(Client, client_table, {