Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 262:ab921dc53ccd
Added nicer command-line item adding:
passing no arguments will enter an interactive more which asks for
each property in turn. While I was at it, I fixed an implementation
problem WRT the spec - I wasn't raising a ValueError if the key
property was missing from a create(). Also added a protected=boolean
argument to getprops() so we can list only the mutable properties
(defaults to yes, which lists the immutables).
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 04 Oct 2001 02:12:42 +0000 |
| parents | 8827f5931ea8 |
| children | a671e5917b33 |
comparison
equal
deleted
inserted
replaced
| 261:0ca5381a72b5 | 262:ab921dc53ccd |
|---|---|
| 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.19 2001-08-29 04:47:18 richard Exp $ | 18 # $Id: hyperdb.py,v 1.20 2001-10-04 02:12:42 richard Exp $ |
| 19 | 19 |
| 20 # standard python modules | 20 # standard python modules |
| 21 import cPickle, re, string | 21 import cPickle, re, string |
| 22 | 22 |
| 23 # roundup modules | 23 # roundup modules |
| 198 raise TypeError, 'new property "%s" not an Interval'% key | 198 raise TypeError, 'new property "%s" not an Interval'% key |
| 199 | 199 |
| 200 for key, prop in self.properties.items(): | 200 for key, prop in self.properties.items(): |
| 201 if propvalues.has_key(key): | 201 if propvalues.has_key(key): |
| 202 continue | 202 continue |
| 203 if key == self.key: | |
| 204 raise ValueError, 'key property "%s" is required'%key | |
| 203 if isinstance(prop, Multilink): | 205 if isinstance(prop, Multilink): |
| 204 propvalues[key] = [] | 206 propvalues[key] = [] |
| 205 else: | 207 else: |
| 206 propvalues[key] = None | 208 propvalues[key] = None |
| 207 | 209 |
| 732 """ | 734 """ |
| 733 return self.db.countnodes(self.classname) | 735 return self.db.countnodes(self.classname) |
| 734 | 736 |
| 735 # Manipulating properties: | 737 # Manipulating properties: |
| 736 | 738 |
| 737 def getprops(self): | 739 def getprops(self, protected=1): |
| 738 """Return a dictionary mapping property names to property objects.""" | 740 """Return a dictionary mapping property names to property objects. |
| 741 If the "protected" flag is true, we include protected properties - | |
| 742 those which may not be modified.""" | |
| 739 d = self.properties.copy() | 743 d = self.properties.copy() |
| 740 d['id'] = String() | 744 if protected: |
| 745 d['id'] = String() | |
| 741 return d | 746 return d |
| 742 | 747 |
| 743 def addprop(self, **properties): | 748 def addprop(self, **properties): |
| 744 """Add properties to this class. | 749 """Add properties to this class. |
| 745 | 750 |
| 793 cl.create(name=option[i], order=i) | 798 cl.create(name=option[i], order=i) |
| 794 return hyperdb.Link(name) | 799 return hyperdb.Link(name) |
| 795 | 800 |
| 796 # | 801 # |
| 797 # $Log: not supported by cvs2svn $ | 802 # $Log: not supported by cvs2svn $ |
| 803 # Revision 1.19 2001/08/29 04:47:18 richard | |
| 804 # Fixed CGI client change messages so they actually include the properties | |
| 805 # changed (again). | |
| 806 # | |
| 798 # Revision 1.18 2001/08/16 07:34:59 richard | 807 # Revision 1.18 2001/08/16 07:34:59 richard |
| 799 # better CGI text searching - but hidden filter fields are disappearing... | 808 # better CGI text searching - but hidden filter fields are disappearing... |
| 800 # | 809 # |
| 801 # Revision 1.17 2001/08/16 06:59:58 richard | 810 # Revision 1.17 2001/08/16 06:59:58 richard |
| 802 # all searches use re now - and they're all case insensitive | 811 # all searches use re now - and they're all case insensitive |
