[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r6987 - in trunk/gnue-common/src/datasources: . drivers/DBSIG2
From: |
johannes |
Subject: |
[gnue] r6987 - in trunk/gnue-common/src/datasources: . drivers/DBSIG2 |
Date: |
Thu, 10 Feb 2005 13:18:07 -0600 (CST) |
Author: johannes
Date: 2005-02-10 13:18:07 -0600 (Thu, 10 Feb 2005)
New Revision: 6987
Modified:
trunk/gnue-common/src/datasources/GDataSource.py
trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
Log:
Added 'ignorecase'-attribute to <sortfield>-tag, allowing case-insensitive
ordering
Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py 2005-02-10 19:01:54 UTC
(rev 6986)
+++ trunk/gnue-common/src/datasources/GDataSource.py 2005-02-10 19:18:07 UTC
(rev 6987)
@@ -134,7 +134,7 @@
self.__getSortOrder ()
if self.sorting:
- for (field, order) in self.sorting:
+ for field in [item ['name'] for item in self.sorting]:
self._fieldReferences [field] = True
return GObjects.GObj._buildObject(self)
@@ -449,7 +449,9 @@
if child is not None:
self.sorting = []
for item in child.findChildrenOfType ('GCSortField'):
- self.sorting.append ((item.name, item.descending))
+ self.sorting.append ({'name' : item.name,
+ 'descending': item.descending,
+ 'ignorecase': item.ignorecase})
# otherwise let's investigate the order_by attribute given
elif hasattr (self, 'order_by'):
@@ -483,7 +485,9 @@
if desc:
item = item [:-5].strip ()
- result.append ((item, desc))
+ # Since the old 'order_by' format does *not* support 'ignorecase' we
+ # will use 'False' as default
+ result.append ({'name': item, 'descending': desc})
# Well, order_by is already a sequence. So we've to make sure it's a
# sequence of tuples with fieldname and direction.
@@ -491,10 +495,16 @@
for item in order_by:
if isinstance (item, types.StringType) or \
isinstance (item, types.UnicodeType):
- result.append ((item, False))
- else:
+ result.append ({'name':item})
+
+ elif isinstance (item, types.DictType):
result.append (item)
+ else:
+ element = {'name': item [0]}
+ if len (item) > 1: element ['descending'] = item [1]
+ if len (item) > 2: element ['ignorecase'] = item [2]
+
else:
raise MarkupError, \
(u_("Unknown type/format of 'order-by' attribute"), self._url,
@@ -693,12 +703,12 @@
'ParentTags': None },
'sortorder': {
- 'BaseClass': GSortOrder,
+ 'BaseClass': GCSortOrder,
'Attributes': {},
'ParentTags': ('datasource',),
},
'sortfield': {
- 'BaseClass': GSortField,
+ 'BaseClass': GCSortField,
'Attributes': {
'name': {
'Required': True,
@@ -713,6 +723,12 @@
'Default' : False,
'Typecast': GTypecast.boolean,
},
+ 'ignorecase': {
+ 'Default' : False,
+ 'Typecast': GTypecast.boolean,
+ 'Description': 'Selects wether the ordering is case-sensitive '
+ 'or not.',
+ },
},
'ParentTags': ('sortorder',),
},
@@ -795,7 +811,7 @@
# Classes for implementing sort options
# =============================================================================
-class GSortOrder (GObjects.GObj):
+class GCSortOrder (GObjects.GObj):
def __init__ (self, parent = None):
GObjects.GObj.__init__ (self, parent, 'GCSortOrder')
self.sorting = []
@@ -803,10 +819,12 @@
def _build (self):
for item in self.findChildrenOfType ('GCSortField'):
- self.sorting.append ((item.name, item.descending))
+ self.sorting.append ({'name': item.name,
+ 'descending': item.descending,
+ 'ignorecase': item.ignorecase})
-class GSortField (GObjects.GObj):
+class GCSortField (GObjects.GObj):
def __init__ (self, parent = None):
GObjects.GObj.__init__ (self, parent, 'GCSortField')
Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
2005-02-10 19:01:54 UTC (rev 6986)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
2005-02-10 19:18:07 UTC (rev 6987)
@@ -340,7 +340,15 @@
whereClause)
if hasattr (self, 'sorting') and not forDetail and self.sorting:
- order = ["%s%s" % (f, d and ' desc' or '') for (f, d) in self.sorting]
+ order = []
+ for item in self.sorting:
+ field = item ['name']
+ descending = item.get ('descending') or False
+ ignorecase = item.get ('ignorecase') or False
+
+ fmt = ignorecase and "LOWER(%s)%s" or "%s%s"
+ order.append (fmt % (field, descending and ' desc' or ''))
+
q = "%s ORDER BY %s " % (q, string.join (order, ", "))
gDebug (5, q)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r6987 - in trunk/gnue-common/src/datasources: . drivers/DBSIG2,
johannes <=