[SQL-CVS] SQLObject/SQLObject Style.py,1.3,1.4
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <ian...@us...> - 2003-06-28 22:20:41
|
Update of /cvsroot/sqlobject/SQLObject/SQLObject In directory sc8-pr-cvs1:/tmp/cvs-serv1550 Modified Files: Style.py Log Message: Added MixedCaseStyle, tweaked styles Index: Style.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Style.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Style.py 12 May 2003 01:58:21 -0000 1.3 --- Style.py 28 Jun 2003 22:20:37 -0000 1.4 *************** *** 1,5 **** import re ! __all__ = ["Style", "MixedCaseUnderscoreStyle", "DefaultStyle"] class Style(object): --- 1,6 ---- import re ! __all__ = ["Style", "MixedCaseUnderscoreStyle", "DefaultStyle", ! "MixedCaseStyle"] class Style(object): *************** *** 16,20 **** pythonClassToDBTable=None, dbTableToPythonClass=None, ! idForTable=None): if pythonAttrToDBColumn: self.pythonAttrToDBColumn = lambda a, s=self: pythonAttrToDBColumn(s, a) --- 17,22 ---- pythonClassToDBTable=None, dbTableToPythonClass=None, ! idForTable=None, ! longID=False): if pythonAttrToDBColumn: self.pythonAttrToDBColumn = lambda a, s=self: pythonAttrToDBColumn(s, a) *************** *** 27,30 **** --- 29,33 ---- if idForTable: self.idForTable = lambda a, s=self: idForTable(s, a) + self.longID = longID def pythonAttrToDBColumn(self, attr): *************** *** 41,48 **** def idForTable(self, table): ! return 'id' def pythonClassToAttr(self, className): ! return className[0].lower() + className[1:] def instanceAttrToIDAttr(self, attr): --- 44,54 ---- def idForTable(self, table): ! if self.longID: ! return self.tableReference(table) ! else: ! return 'id' def pythonClassToAttr(self, className): ! return lowerword(className) def instanceAttrToIDAttr(self, attr): *************** *** 80,89 **** DefaultStyle = MixedCaseUnderscoreStyle ! def longID(self, table): """ ! Use SomeStyle(idForTable=longID) to use this. This will ! make table IDs use the full table, like person_id. """ ! return defaultStyle = DefaultStyle() --- 86,107 ---- DefaultStyle = MixedCaseUnderscoreStyle ! class MixedCaseStyle(Style): ! """ ! This style leaves columns as mixed-case, and uses long ! ID names (like ProductID instead of simply id). """ ! ! def pythonAttrToDBColumn(self, attr): ! return capword(attr) ! ! def dbColumnToPythonAttr(self, col): ! return lowerword(col) ! ! def dbTableToPythonClass(self, table): ! return capword(table) ! ! def tableReference(self, table): ! return table + "ID" defaultStyle = DefaultStyle() *************** *** 118,121 **** --- 136,145 ---- else: return '_%s' % m + + def capword(s): + return s[0].upper() + s[1:] + + def lowerword(s): + return s[0].lower() + s[1:] _underToMixedRE = re.compile('_.') |