Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 555:5fd94347c6f2
Journal entries for link and multilink properties can now be switched on or off.
| author | Roche Compaan <rochecompaan@users.sourceforge.net> |
|---|---|
| date | Sat, 19 Jan 2002 13:16:04 +0000 |
| parents | 22e0edf7da6e |
| children | dfac856502d1 |
comparison
equal
deleted
inserted
replaced
| 554:7e7b4183a8bd | 555:5fd94347c6f2 |
|---|---|
| 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.49 2002-01-16 07:02:57 richard Exp $ | 18 # $Id: hyperdb.py,v 1.50 2002-01-19 13:16:04 rochecompaan Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Hyperdatabase implementation, especially field types. | 21 Hyperdatabase implementation, especially field types. |
| 22 """ | 22 """ |
| 23 | 23 |
| 52 return '<%s>'%self.__class__ | 52 return '<%s>'%self.__class__ |
| 53 | 53 |
| 54 class Link: | 54 class Link: |
| 55 """An object designating a Link property that links to a | 55 """An object designating a Link property that links to a |
| 56 node in a specified class.""" | 56 node in a specified class.""" |
| 57 def __init__(self, classname): | 57 def __init__(self, classname, do_journal='no'): |
| 58 self.classname = classname | 58 self.classname = classname |
| 59 self.do_journal = do_journal == 'yes' | |
| 59 def __repr__(self): | 60 def __repr__(self): |
| 60 return '<%s to "%s">'%(self.__class__, self.classname) | 61 return '<%s to "%s">'%(self.__class__, self.classname) |
| 61 | 62 |
| 62 class Multilink: | 63 class Multilink: |
| 63 """An object designating a Multilink property that links | 64 """An object designating a Multilink property that links |
| 64 to nodes in a specified class. | 65 to nodes in a specified class. |
| 65 """ | 66 """ |
| 66 def __init__(self, classname): | 67 def __init__(self, classname, do_journal='no'): |
| 67 self.classname = classname | 68 self.classname = classname |
| 69 self.do_journal = do_journal == 'yes' | |
| 68 def __repr__(self): | 70 def __repr__(self): |
| 69 return '<%s to "%s">'%(self.__class__, self.classname) | 71 return '<%s to "%s">'%(self.__class__, self.classname) |
| 70 | 72 |
| 71 class DatabaseError(ValueError): | 73 class DatabaseError(ValueError): |
| 72 pass | 74 pass |
| 307 | 309 |
| 308 # save off the value | 310 # save off the value |
| 309 propvalues[key] = value | 311 propvalues[key] = value |
| 310 | 312 |
| 311 # register the link with the newly linked node | 313 # register the link with the newly linked node |
| 312 self.db.addjournal(link_class, value, 'link', | 314 if self.properties[key].do_journal: |
| 313 (self.classname, newid, key)) | 315 self.db.addjournal(link_class, value, 'link', |
| 316 (self.classname, newid, key)) | |
| 314 | 317 |
| 315 elif isinstance(prop, Multilink): | 318 elif isinstance(prop, Multilink): |
| 316 if type(value) != type([]): | 319 if type(value) != type([]): |
| 317 raise TypeError, 'new property "%s" not a list of ids'%key | 320 raise TypeError, 'new property "%s" not a list of ids'%key |
| 318 link_class = self.properties[key].classname | 321 link_class = self.properties[key].classname |
| 334 # handle additions | 337 # handle additions |
| 335 for id in value: | 338 for id in value: |
| 336 if not self.db.hasnode(link_class, id): | 339 if not self.db.hasnode(link_class, id): |
| 337 raise IndexError, '%s has no node %s'%(link_class, id) | 340 raise IndexError, '%s has no node %s'%(link_class, id) |
| 338 # register the link with the newly linked node | 341 # register the link with the newly linked node |
| 339 self.db.addjournal(link_class, id, 'link', | 342 if self.properties[key].do_journal: |
| 340 (self.classname, newid, key)) | 343 self.db.addjournal(link_class, id, 'link', |
| 344 (self.classname, newid, key)) | |
| 341 | 345 |
| 342 elif isinstance(prop, String): | 346 elif isinstance(prop, String): |
| 343 if type(value) != type(''): | 347 if type(value) != type(''): |
| 344 raise TypeError, 'new property "%s" not a string'%key | 348 raise TypeError, 'new property "%s" not a string'%key |
| 345 | 349 |
| 503 key, value, self.properties[key].classname) | 507 key, value, self.properties[key].classname) |
| 504 | 508 |
| 505 if not self.db.hasnode(link_class, value): | 509 if not self.db.hasnode(link_class, value): |
| 506 raise IndexError, '%s has no node %s'%(link_class, value) | 510 raise IndexError, '%s has no node %s'%(link_class, value) |
| 507 | 511 |
| 508 # register the unlink with the old linked node | 512 if self.properties[key].do_journal: |
| 509 if node[key] is not None: | 513 # register the unlink with the old linked node |
| 510 self.db.addjournal(link_class, node[key], 'unlink', | 514 if node[key] is not None: |
| 511 (self.classname, nodeid, key)) | 515 self.db.addjournal(link_class, node[key], 'unlink', |
| 512 | 516 (self.classname, nodeid, key)) |
| 513 # register the link with the newly linked node | 517 |
| 514 if value is not None: | 518 # register the link with the newly linked node |
| 515 self.db.addjournal(link_class, value, 'link', | 519 if value is not None: |
| 516 (self.classname, nodeid, key)) | 520 self.db.addjournal(link_class, value, 'link', |
| 521 (self.classname, nodeid, key)) | |
| 517 | 522 |
| 518 elif isinstance(prop, Multilink): | 523 elif isinstance(prop, Multilink): |
| 519 if type(value) != type([]): | 524 if type(value) != type([]): |
| 520 raise TypeError, 'new property "%s" not a list of ids'%key | 525 raise TypeError, 'new property "%s" not a list of ids'%key |
| 521 link_class = self.properties[key].classname | 526 link_class = self.properties[key].classname |
| 541 l = [] | 546 l = [] |
| 542 for id in l[:]: | 547 for id in l[:]: |
| 543 if id in value: | 548 if id in value: |
| 544 continue | 549 continue |
| 545 # register the unlink with the old linked node | 550 # register the unlink with the old linked node |
| 546 self.db.addjournal(link_class, id, 'unlink', | 551 if self.properties[key].do_journal: |
| 547 (self.classname, nodeid, key)) | 552 self.db.addjournal(link_class, id, 'unlink', |
| 553 (self.classname, nodeid, key)) | |
| 548 l.remove(id) | 554 l.remove(id) |
| 549 | 555 |
| 550 # handle additions | 556 # handle additions |
| 551 for id in value: | 557 for id in value: |
| 552 if not self.db.hasnode(link_class, id): | 558 if not self.db.hasnode(link_class, id): |
| 553 raise IndexError, '%s has no node %s'%(link_class, id) | 559 raise IndexError, '%s has no node %s'%( |
| 560 link_class, id) | |
| 554 if id in l: | 561 if id in l: |
| 555 continue | 562 continue |
| 556 # register the link with the newly linked node | 563 # register the link with the newly linked node |
| 557 self.db.addjournal(link_class, id, 'link', | 564 if self.properties[key].do_journal: |
| 558 (self.classname, nodeid, key)) | 565 self.db.addjournal(link_class, id, 'link', |
| 566 (self.classname, nodeid, key)) | |
| 559 l.append(id) | 567 l.append(id) |
| 560 | 568 |
| 561 elif isinstance(prop, String): | 569 elif isinstance(prop, String): |
| 562 if value is not None and type(value) != type(''): | 570 if value is not None and type(value) != type(''): |
| 563 raise TypeError, 'new property "%s" not a string'%key | 571 raise TypeError, 'new property "%s" not a string'%key |
| 1045 cl.create(name=option[i], order=i) | 1053 cl.create(name=option[i], order=i) |
| 1046 return hyperdb.Link(name) | 1054 return hyperdb.Link(name) |
| 1047 | 1055 |
| 1048 # | 1056 # |
| 1049 # $Log: not supported by cvs2svn $ | 1057 # $Log: not supported by cvs2svn $ |
| 1058 # Revision 1.49 2002/01/16 07:02:57 richard | |
| 1059 # . lots of date/interval related changes: | |
| 1060 # - more relaxed date format for input | |
| 1061 # | |
| 1050 # Revision 1.48 2002/01/14 06:32:34 richard | 1062 # Revision 1.48 2002/01/14 06:32:34 richard |
| 1051 # . #502951 ] adding new properties to old database | 1063 # . #502951 ] adding new properties to old database |
| 1052 # | 1064 # |
| 1053 # Revision 1.47 2002/01/14 02:20:15 richard | 1065 # Revision 1.47 2002/01/14 02:20:15 richard |
| 1054 # . changed all config accesses so they access either the instance or the | 1066 # . changed all config accesses so they access either the instance or the |
