|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -#$Id: back_anydbm.py,v 1.197 2006-03-03 02:51:13 richard Exp $ |
| 18 | +#$Id: back_anydbm.py,v 1.198 2006-04-27 01:39:47 richard Exp $ |
19 | 19 | '''This module defines a backend that saves the hyperdatabase in a |
20 | 20 | database chosen by anydbm. It is guaranteed to always be available in python |
21 | 21 | versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several |
@@ -2023,7 +2023,15 @@ class FileClass(hyperdb.FileClass, Class): |
2023 | 2023 | "default_mime_type" class attribute, which may be overridden by each |
2024 | 2024 | node if the class defines a "type" String property. |
2025 | 2025 | ''' |
2026 | | - default_mime_type = 'text/plain' |
| 2026 | + def __init__(self, db, classname, **properties): |
| 2027 | + '''The newly-created class automatically includes the "content" |
| 2028 | + and "type" properties. |
| 2029 | + ''' |
| 2030 | + if not properties.has_key('content'): |
| 2031 | + properties['content'] = hyperdb.String(indexme='yes') |
| 2032 | + if not properties.has_key('type'): |
| 2033 | + properties['type'] = hyperdb.String() |
| 2034 | + Class.__init__(self, db, classname, **properties) |
2027 | 2035 |
|
2028 | 2036 | def create(self, **propvalues): |
2029 | 2037 | ''' Snarf the "content" propvalue and store in a file |
@@ -2093,47 +2101,37 @@ def set(self, itemid, **propvalues): |
2093 | 2101 |
|
2094 | 2102 | # do content? |
2095 | 2103 | if content: |
2096 | | - # store and index |
| 2104 | + # store and possibly index |
2097 | 2105 | self.db.storefile(self.classname, itemid, None, content) |
2098 | | - mime_type = None |
2099 | | - if self.getprops().has_key('type'): |
2100 | | - mime_type = propvalues.get('type', self.get(itemid, 'type')) |
2101 | | - if not mime_type: |
2102 | | - mime_type = self.default_mime_type |
2103 | | - self.db.indexer.add_text((self.classname, itemid, 'content'), |
2104 | | - content, mime_type) |
2105 | | - |
| 2106 | + if self.properties['content'].indexme: |
| 2107 | + mime_type = self.get(itemid, 'type', self.default_mime_type) |
| 2108 | + self.db.indexer.add_text((self.classname, itemid, 'content'), |
| 2109 | + content, mime_type) |
2106 | 2110 | propvalues['content'] = content |
2107 | 2111 |
|
2108 | 2112 | # fire reactors |
2109 | 2113 | self.fireReactors('set', itemid, oldvalues) |
2110 | 2114 | return propvalues |
2111 | 2115 |
|
2112 | | - def getprops(self, protected=1): |
2113 | | - '''In addition to the actual properties on the node, these methods |
2114 | | - provide the "content" property. If the "protected" flag is true, |
2115 | | - we include protected properties - those which may not be |
2116 | | - modified. |
2117 | | -
|
2118 | | - Note that the content prop is indexed separately, hence no indexme. |
2119 | | - ''' |
2120 | | - d = Class.getprops(self, protected=protected).copy() |
2121 | | - d['content'] = hyperdb.String() |
2122 | | - return d |
2123 | | - |
2124 | 2116 | def index(self, nodeid): |
2125 | | - '''Add (or refresh) the node to search indexes. |
| 2117 | + ''' Add (or refresh) the node to search indexes. |
2126 | 2118 |
|
2127 | | - Pass on the content-type property for the content property. |
| 2119 | + Use the content-type property for the content property. |
2128 | 2120 | ''' |
2129 | | - Class.index(self, nodeid) |
2130 | | - mime_type = None |
2131 | | - if self.getprops().has_key('type'): |
2132 | | - mime_type = self.get(nodeid, 'type', self.default_mime_type) |
2133 | | - if not mime_type: |
2134 | | - mime_type = self.default_mime_type |
2135 | | - self.db.indexer.add_text((self.classname, nodeid, 'content'), |
2136 | | - str(self.get(nodeid, 'content')), mime_type) |
| 2121 | + # find all the String properties that have indexme |
| 2122 | + for prop, propclass in self.getprops().items(): |
| 2123 | + if prop == 'content' and propclass.indexme: |
| 2124 | + mime_type = self.get(nodeid, 'type', self.default_mime_type) |
| 2125 | + self.db.indexer.add_text((self.classname, nodeid, 'content'), |
| 2126 | + str(self.get(nodeid, 'content')), mime_type) |
| 2127 | + elif isinstance(propclass, hyperdb.String) and propclass.indexme: |
| 2128 | + # index them under (classname, nodeid, property) |
| 2129 | + try: |
| 2130 | + value = str(self.get(nodeid, prop)) |
| 2131 | + except IndexError: |
| 2132 | + # node has been destroyed |
| 2133 | + continue |
| 2134 | + self.db.indexer.add_text((self.classname, nodeid, prop), value) |
2137 | 2135 |
|
2138 | 2136 | # deviation from spec - was called ItemClass |
2139 | 2137 | class IssueClass(Class, roundupdb.IssueClass): |
|
0 commit comments