Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 627:952679be9e2c
Added simple editing for classes that don't define a templated interface.
- access using the admin "class list" interface
- limited to admin-only
- requires the csv module from object-craft (url given if it's missing)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 20 Feb 2002 05:05:29 +0000 |
| parents | 9431715612ac |
| children | 923de4949369 |
comparison
equal
deleted
inserted
replaced
| 626:300e17e7045c | 627:952679be9e2c |
|---|---|
| 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.55 2002-02-15 07:27:12 richard Exp $ | 18 # $Id: hyperdb.py,v 1.56 2002-02-20 05:05:28 richard Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Hyperdatabase implementation, especially field types. | 21 Hyperdatabase implementation, especially field types. |
| 22 """ | 22 """ |
| 23 | 23 |
| 488 | 488 |
| 489 node = self.db.getnode(self.classname, nodeid) | 489 node = self.db.getnode(self.classname, nodeid) |
| 490 if node.has_key(self.db.RETIRED_FLAG): | 490 if node.has_key(self.db.RETIRED_FLAG): |
| 491 raise IndexError | 491 raise IndexError |
| 492 num_re = re.compile('^\d+$') | 492 num_re = re.compile('^\d+$') |
| 493 set = {} | |
| 493 for key, value in propvalues.items(): | 494 for key, value in propvalues.items(): |
| 494 # check to make sure we're not duplicating an existing key | 495 # check to make sure we're not duplicating an existing key |
| 495 if key == self.key and node[key] != value: | 496 if key == self.key and node[key] != value: |
| 496 try: | 497 try: |
| 497 self.lookup(value) | 498 self.lookup(value) |
| 503 # this will raise the KeyError if the property isn't valid | 504 # this will raise the KeyError if the property isn't valid |
| 504 # ... we don't use getprops() here because we only care about | 505 # ... we don't use getprops() here because we only care about |
| 505 # the writeable properties. | 506 # the writeable properties. |
| 506 prop = self.properties[key] | 507 prop = self.properties[key] |
| 507 | 508 |
| 509 # if the value's the same as the existing value, no sense in | |
| 510 # doing anything | |
| 511 if value == node[key]: | |
| 512 del propvalues[key] | |
| 513 continue | |
| 514 | |
| 515 # do stuff based on the prop type | |
| 508 if isinstance(prop, Link): | 516 if isinstance(prop, Link): |
| 509 link_class = self.properties[key].classname | 517 link_class = self.properties[key].classname |
| 510 # if it isn't a number, it's a key | 518 # if it isn't a number, it's a key |
| 511 if type(value) != type(''): | 519 if type(value) != type(''): |
| 512 raise ValueError, 'link value must be String' | 520 raise ValueError, 'link value must be String' |
| 596 raise TypeError, 'new property "%s" not an Interval'% key | 604 raise TypeError, 'new property "%s" not an Interval'% key |
| 597 propvalues[key] = value = value.get_tuple() | 605 propvalues[key] = value = value.get_tuple() |
| 598 | 606 |
| 599 node[key] = value | 607 node[key] = value |
| 600 | 608 |
| 609 # nothing to do? | |
| 610 if not propvalues: | |
| 611 return | |
| 612 | |
| 613 # do the set, and journal it | |
| 601 self.db.setnode(self.classname, nodeid, node) | 614 self.db.setnode(self.classname, nodeid, node) |
| 602 self.db.addjournal(self.classname, nodeid, 'set', propvalues) | 615 self.db.addjournal(self.classname, nodeid, 'set', propvalues) |
| 603 | 616 |
| 604 def retire(self, nodeid): | 617 def retire(self, nodeid): |
| 605 """Retire a node. | 618 """Retire a node. |
| 631 'tag' is the journaltag specified when the database was opened. | 644 'tag' is the journaltag specified when the database was opened. |
| 632 """ | 645 """ |
| 633 return self.db.getjournal(self.classname, nodeid) | 646 return self.db.getjournal(self.classname, nodeid) |
| 634 | 647 |
| 635 # Locating nodes: | 648 # Locating nodes: |
| 649 def hasnode(self, nodeid): | |
| 650 '''Determine if the given nodeid actually exists | |
| 651 ''' | |
| 652 return self.db.hasnode(self.classname, nodeid) | |
| 636 | 653 |
| 637 def setkey(self, propname): | 654 def setkey(self, propname): |
| 638 """Select a String property of this class to be the key property. | 655 """Select a String property of this class to be the key property. |
| 639 | 656 |
| 640 'propname' must be the name of a String property of this class or | 657 'propname' must be the name of a String property of this class or |
| 1064 cl.create(name=option[i], order=i) | 1081 cl.create(name=option[i], order=i) |
| 1065 return hyperdb.Link(name) | 1082 return hyperdb.Link(name) |
| 1066 | 1083 |
| 1067 # | 1084 # |
| 1068 # $Log: not supported by cvs2svn $ | 1085 # $Log: not supported by cvs2svn $ |
| 1086 # Revision 1.55 2002/02/15 07:27:12 richard | |
| 1087 # Oops, precedences around the way w0rng. | |
| 1088 # | |
| 1069 # Revision 1.54 2002/02/15 07:08:44 richard | 1089 # Revision 1.54 2002/02/15 07:08:44 richard |
| 1070 # . Alternate email addresses are now available for users. See the MIGRATION | 1090 # . Alternate email addresses are now available for users. See the MIGRATION |
| 1071 # file for info on how to activate the feature. | 1091 # file for info on how to activate the feature. |
| 1072 # | 1092 # |
| 1073 # Revision 1.53 2002/01/22 07:21:13 richard | 1093 # Revision 1.53 2002/01/22 07:21:13 richard |
