Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 3476:1142dafe0d7f
added setorderprop() and setlabelprop() to Class (lots of patches)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 20 Jan 2006 02:40:56 +0000 |
| parents | e01bc6d65fa9 |
| children | e4177cf4d30d |
comparison
equal
deleted
inserted
replaced
| 3475:addbe69ff58b | 3476:1142dafe0d7f |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 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 $ |
| 19 | 19 |
| 20 """Hyperdatabase implementation, especially field types. | 20 """Hyperdatabase implementation, especially field types. |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 589 None, or a TypeError is raised. The values of the key property on | 589 None, or a TypeError is raised. The values of the key property on |
| 590 all existing nodes must be unique or a ValueError is raised. | 590 all existing nodes must be unique or a ValueError is raised. |
| 591 """ | 591 """ |
| 592 raise NotImplementedError | 592 raise NotImplementedError |
| 593 | 593 |
| 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 | |
| 594 def getkey(self): | 610 def getkey(self): |
| 595 """Return the name of the key property for this class or None.""" | 611 """Return the name of the key property for this class or None.""" |
| 596 raise NotImplementedError | 612 raise NotImplementedError |
| 597 | 613 |
| 598 def labelprop(self, default_to_id=0): | 614 def labelprop(self, default_to_id=0): |
| 599 """Return the property name for a label for the given node. | 615 """Return the property name for a label for the given node. |
| 600 | 616 |
| 601 This method attempts to generate a consistent label for the node. | 617 This method attempts to generate a consistent label for the node. |
| 602 It tries the following in order: | 618 It tries the following in order: |
| 603 | 619 |
| 620 0. self._labelprop if set | |
| 604 1. key property | 621 1. key property |
| 605 2. "name" property | 622 2. "name" property |
| 606 3. "title" property | 623 3. "title" property |
| 607 4. first property from the sorted property name list | 624 4. first property from the sorted property name list |
| 608 """ | 625 """ |
| 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 () | |
| 610 | 659 |
| 611 def lookup(self, keyvalue): | 660 def lookup(self, keyvalue): |
| 612 """Locate a particular node by its key property and return its id. | 661 """Locate a particular node by its key property and return its id. |
| 613 | 662 |
| 614 If this class has no key property, a TypeError is raised. If the | 663 If this class has no key property, a TypeError is raised. If the |
