Skip to content

Commit 57da1e5

Browse files
author
Richard Jones
committed
added setorderprop() and setlabelprop() to Class (lots of patches)
1 parent 10a7ee4 commit 57da1e5

File tree

7 files changed

+102
-110
lines changed

7 files changed

+102
-110
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Feature:
1717
- allow preselection of values in templating menu()s (sf patch 1396085)
1818
- display the query name in the header (sf feature 1298535 / patch 1349387)
1919
- classhelp works with Link properties now (sf bug 1410290)
20+
- added setorderprop() and setlabelprop() to Class (lots of patches)
2021

2122
Fixed:
2223
- MySQL now creates String columns using the TEXT column type

doc/customizing.txt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.188 $
5+
:Version: $Revision: 1.189 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -352,8 +352,10 @@ The ``schema.py`` module contains two functions:
352352
The "classic" schema
353353
--------------------
354354

355-
The "classic" schema looks like this (see below for the meaning
356-
of ``'setkey'``)::
355+
The "classic" schema looks like this (see section `setkey(property)`_
356+
below for the meaning of ``'setkey'`` -- you may also want to look into
357+
the sections `setlabelprop(property)`_ and `setorderprop(property)`_ for
358+
specifying (default) labelling and ordering of classes.)::
357359

358360
pri = Class(db, "priority", name=String(), order=String())
359361
pri.setkey("name")
@@ -548,12 +550,37 @@ or::
548550

549551
Note, the same thing can be done in the web and e-mail interfaces.
550552

551-
If a class does not have an "order" property, the key is also used to
552-
sort instances of the class when it is rendered in the user interface.
553-
(If a class has no "order" property, sorting is by the labelproperty of
554-
the class. This is computed, in order of precedence, as the key, the
555-
"name", the "title", or the first property alphabetically.)
553+
setlabelprop(property)
554+
~~~~~~~~~~~~~~~~~~~~~~
555+
556+
Select a property of the class to be the label property. The label
557+
property is used whereever an item should be uniquely identified, e.g.,
558+
when displaying a link to an item. If setlabelprop is not specified for
559+
a class, the following values are tried for the label:
560+
561+
* the key of the class (see the `setkey(property)`_ section above)
562+
* the "name" property
563+
* the "title" property
564+
* the first property from the sorted property name list
565+
566+
So in most cases you can get away without specifying setlabelprop
567+
explicitly.
568+
569+
setorderprop(property)
570+
~~~~~~~~~~~~~~~~~~~~~~
571+
572+
Select a property of the class to be the order property. The order
573+
property is used whenever using a default sort order for the class,
574+
e.g., when grouping or sorting class A by a link to class B in the user
575+
interface, the order property of class B is used for sorting. If
576+
setorderprop is not specified for a class, the following values are tried
577+
for the order property:
578+
579+
* the property named "order"
580+
* the label property (see `setlabelprop(property)`_ above)
556581

582+
So in most cases you can get away without specifying setorderprop
583+
explicitly.
557584

558585
create(information)
559586
~~~~~~~~~~~~~~~~~~~

roundup/backends/back_anydbm.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.191 2006-01-13 00:05:46 richard Exp $
18+
#$Id: back_anydbm.py,v 1.192 2006-01-20 02:40:56 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -1380,31 +1380,6 @@ def getkey(self):
13801380
'''Return the name of the key property for this class or None.'''
13811381
return self.key
13821382

1383-
def labelprop(self, default_to_id=0):
1384-
'''Return the property name for a label for the given node.
1385-
1386-
This method attempts to generate a consistent label for the node.
1387-
It tries the following in order:
1388-
1389-
1. key property
1390-
2. "name" property
1391-
3. "title" property
1392-
4. first property from the sorted property name list
1393-
'''
1394-
k = self.getkey()
1395-
if k:
1396-
return k
1397-
props = self.getprops()
1398-
if props.has_key('name'):
1399-
return 'name'
1400-
elif props.has_key('title'):
1401-
return 'title'
1402-
if default_to_id:
1403-
return 'id'
1404-
props = props.keys()
1405-
props.sort()
1406-
return props[0]
1407-
14081383
# TODO: set up a separate index db file for this? profile?
14091384
def lookup(self, keyvalue):
14101385
'''Locate a particular node by its key property and return its id.
@@ -1786,12 +1761,8 @@ def filter(self, search_matches, filterspec, sort=(None,None),
17861761
elif isinstance(propclass, hyperdb.Link):
17871762
lcn = propclass.classname
17881763
link = self.db.classes[lcn]
1789-
key = None
1790-
if link.getprops().has_key('order'):
1791-
key = 'order'
1792-
elif link.getkey():
1793-
key = link.getkey()
1794-
if key:
1764+
key = link.orderprop()
1765+
if key!='id':
17951766
if not lcache.has_key(v):
17961767
# open the link class db if it's not already
17971768
if lcldb is None:

roundup/backends/back_metakit.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.98 2005-10-07 05:35:04 richard Exp $
1+
# $Id: back_metakit.py,v 1.99 2006-01-20 02:40:56 richard Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -1386,11 +1386,7 @@ def ff(row, r=regexes):
13861386
lv = linkclass.getview()
13871387
lv = lv.rename('id', propname)
13881388
v = v.join(lv, prop, 1)
1389-
if linkclass.getprops().has_key('order'):
1390-
propname = 'order'
1391-
else:
1392-
propname = linkclass.labelprop()
1393-
prop = getattr(v, propname)
1389+
prop = getattr(v, linkclass.orderprop())
13941390
if isreversed:
13951391
rev.append(prop)
13961392
sortspec.append(prop)
@@ -1415,31 +1411,6 @@ def hasnode(self, nodeid):
14151411
'''
14161412
return int(nodeid) < self.maxid
14171413

1418-
def labelprop(self, default_to_id=0):
1419-
'''Return the property name for a label for the given node.
1420-
1421-
This method attempts to generate a consistent label for the node.
1422-
It tries the following in order:
1423-
1424-
1. key property
1425-
2. "name" property
1426-
3. "title" property
1427-
4. first property from the sorted property name list
1428-
'''
1429-
k = self.getkey()
1430-
if k:
1431-
return k
1432-
props = self.getprops()
1433-
if props.has_key('name'):
1434-
return 'name'
1435-
elif props.has_key('title'):
1436-
return 'title'
1437-
if default_to_id:
1438-
return 'id'
1439-
props = props.keys()
1440-
props.sort()
1441-
return props[0]
1442-
14431414
def stringFind(self, **requirements):
14441415
'''Locate a particular node by matching a set of its String
14451416
properties in a caseless search.

roundup/backends/back_mysql.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: back_mysql.py,v 1.63 2006-01-13 01:21:14 richard Exp $
1+
#$Id: back_mysql.py,v 1.64 2006-01-20 02:40:56 richard Exp $
22
#
33
# Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <[email protected]>
44
#
@@ -738,14 +738,13 @@ def filter(self, search_matches, filterspec, sort=(None,None),
738738
lcn = props[prop].classname
739739
link = self.db.classes[lcn]
740740
o = '_%s._%s'%(cn, prop)
741-
if link.getprops().has_key('order'):
741+
op = link.orderprop ()
742+
if op != 'id':
742743
tn = '_' + lcn
743744
loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
744745
o, tn))
745-
ordercols.append(tn + '._order')
746-
o = tn + '._order'
747-
else:
748-
ordercols.append(o)
746+
o = tn + '._%s'%op
747+
ordercols.append(o)
749748
elif prop == 'id':
750749
o = '_%s.id'%cn
751750
else:

roundup/backends/rdbms_common.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.160 2006-01-13 00:05:46 richard Exp $
1+
# $Id: rdbms_common.py,v 1.161 2006-01-20 02:40:56 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1848,31 +1848,6 @@ def getkey(self):
18481848
'''Return the name of the key property for this class or None.'''
18491849
return self.key
18501850

1851-
def labelprop(self, default_to_id=0):
1852-
'''Return the property name for a label for the given node.
1853-
1854-
This method attempts to generate a consistent label for the node.
1855-
It tries the following in order:
1856-
1857-
1. key property
1858-
2. "name" property
1859-
3. "title" property
1860-
4. first property from the sorted property name list
1861-
'''
1862-
k = self.getkey()
1863-
if k:
1864-
return k
1865-
props = self.getprops()
1866-
if props.has_key('name'):
1867-
return 'name'
1868-
elif props.has_key('title'):
1869-
return 'title'
1870-
if default_to_id:
1871-
return 'id'
1872-
props = props.keys()
1873-
props.sort()
1874-
return props[0]
1875-
18761851
def lookup(self, keyvalue):
18771852
'''Locate a particular node by its key property and return its id.
18781853
@@ -2224,14 +2199,13 @@ def filter(self, search_matches, filterspec, sort=(None,None),
22242199
lcn = props[prop].classname
22252200
link = self.db.classes[lcn]
22262201
o = '_%s._%s'%(cn, prop)
2227-
if link.getprops().has_key('order'):
2202+
op = link.orderprop()
2203+
if op != 'id':
22282204
tn = '_' + lcn
22292205
loj.append('LEFT OUTER JOIN %s on %s=%s.id'%(tn,
22302206
o, tn))
2231-
ordercols.append(tn + '._order')
2232-
o = tn + '._order'
2233-
else:
2234-
ordercols.append(o)
2207+
o = tn + '._%s'%op
2208+
ordercols.append(o)
22352209
elif prop == 'id':
22362210
o = '_%s.id'%cn
22372211
else:

roundup/hyperdb.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: hyperdb.py,v 1.112 2006-01-13 00:05:46 richard Exp $
18+
# $Id: hyperdb.py,v 1.113 2006-01-20 02:40:56 richard Exp $
1919

2020
"""Hyperdatabase implementation, especially field types.
2121
"""
@@ -591,6 +591,22 @@ def setkey(self, propname):
591591
"""
592592
raise NotImplementedError
593593

594+
def setlabelprop (self, labelprop):
595+
"""Set the label property. Used for override of labelprop
596+
resolution order.
597+
"""
598+
if labelprop not in self.getprops () :
599+
raise ValueError, "Not a property name: %s" % labelprop
600+
self._labelprop = labelprop
601+
602+
def setorderprop (self, orderprop):
603+
"""Set the order property. Used for override of orderprop
604+
resolution order
605+
"""
606+
if orderprop not in self.getprops () :
607+
raise ValueError, "Not a property name: %s" % orderprop
608+
self._orderprop = orderprop
609+
594610
def getkey(self):
595611
"""Return the name of the key property for this class or None."""
596612
raise NotImplementedError
@@ -601,12 +617,45 @@ def labelprop(self, default_to_id=0):
601617
This method attempts to generate a consistent label for the node.
602618
It tries the following in order:
603619
620+
0. self._labelprop if set
604621
1. key property
605622
2. "name" property
606623
3. "title" property
607624
4. first property from the sorted property name list
608625
"""
609-
raise NotImplementedError
626+
if hasattr (self, '_labelprop') :
627+
return self._labelprop
628+
k = self.getkey()
629+
if k:
630+
return k
631+
props = self.getprops()
632+
if props.has_key('name'):
633+
return 'name'
634+
elif props.has_key('title'):
635+
return 'title'
636+
if default_to_id:
637+
return 'id'
638+
props = props.keys()
639+
props.sort()
640+
return props[0]
641+
642+
def orderprop (self):
643+
"""Return the property name to use for sorting for the given node.
644+
645+
This method computes the property for sorting.
646+
It tries the following in order:
647+
648+
0. self._orderprop if set
649+
1. "order" property
650+
2. self.labelprop ()
651+
"""
652+
653+
if hasattr (self, '_orderprop') :
654+
return self._orderprop
655+
props = self.getprops ()
656+
if props.has_key ('order'):
657+
return 'order'
658+
return self.labelprop ()
610659

611660
def lookup(self, keyvalue):
612661
"""Locate a particular node by its key property and return its id.

0 commit comments

Comments
 (0)