Commit 24b2703e authored by Jim Fulton's avatar Jim Fulton

Added a method, getrid, for getting a record id given an object

path. This was added primarily for the purpose of determining if an
object was catalogged.
parent 63317c26
...@@ -29,11 +29,13 @@ from AccessControl import getSecurityManager ...@@ -29,11 +29,13 @@ from AccessControl import getSecurityManager
from AccessControl.DTML import RestrictedDTML from AccessControl.DTML import RestrictedDTML
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from ZCatalogIndexes import ZCatalogIndexes from ZCatalogIndexes import ZCatalogIndexes
from Products.PluginIndexes.common.PluggableIndex import PluggableIndexInterface from Products.PluginIndexes.common.PluggableIndex \
import PluggableIndexInterface
from Products.PluginIndexes.TextIndex.Vocabulary import Vocabulary from Products.PluginIndexes.TextIndex.Vocabulary import Vocabulary
from Products.PluginIndexes.TextIndex import Splitter from Products.PluginIndexes.TextIndex import Splitter
import urllib, os, sys, time, types import urllib, os, sys, time, types
import string import string
from IZCatalog import IZCatalog
manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals()) manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals())
...@@ -52,6 +54,8 @@ def manage_addZCatalog(self, id, title, ...@@ -52,6 +54,8 @@ def manage_addZCatalog(self, id, title,
class ZCatalog(Folder, Persistent, Implicit): class ZCatalog(Folder, Persistent, Implicit):
__implements__ = IZCatalog
"""ZCatalog object """ZCatalog object
A ZCatalog contains arbirary index like references to Zope A ZCatalog contains arbirary index like references to Zope
...@@ -186,7 +190,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -186,7 +190,8 @@ class ZCatalog(Folder, Persistent, Implicit):
threshold=int(threshold) threshold=int(threshold)
self.threshold = threshold self.threshold = threshold
RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Catalog%20Changed') RESPONSE.redirect(
URL1 + '/manage_main?manage_tabs_message=Catalog%20Changed')
def manage_subbingToggle(self, REQUEST, RESPONSE, URL1): def manage_subbingToggle(self, REQUEST, RESPONSE, URL1):
...@@ -196,7 +201,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -196,7 +201,9 @@ class ZCatalog(Folder, Persistent, Implicit):
else: else:
self.threshold = 10000 self.threshold = 10000
RESPONSE.redirect(URL1 + '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Changed') RESPONSE.redirect(
URL1 +
'/manage_catalogAdvanced?manage_tabs_message=Catalog%20Changed')
def manage_catalogObject(self, REQUEST, RESPONSE, URL1, urls=None): def manage_catalogObject(self, REQUEST, RESPONSE, URL1, urls=None):
""" index Zope object(s) that 'urls' point to """ """ index Zope object(s) that 'urls' point to """
...@@ -211,7 +218,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -211,7 +218,9 @@ class ZCatalog(Folder, Persistent, Implicit):
if obj is not None: if obj is not None:
self.catalog_object(obj, url) self.catalog_object(obj, url)
RESPONSE.redirect(URL1 + '/manage_catalogView?manage_tabs_message=Object%20Cataloged') RESPONSE.redirect(
URL1 +
'/manage_catalogView?manage_tabs_message=Object%20Cataloged')
def manage_uncatalogObject(self, REQUEST, RESPONSE, URL1, urls=None): def manage_uncatalogObject(self, REQUEST, RESPONSE, URL1, urls=None):
...@@ -224,7 +233,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -224,7 +233,9 @@ class ZCatalog(Folder, Persistent, Implicit):
for url in urls: for url in urls:
self.uncatalog_object(url) self.uncatalog_object(url)
RESPONSE.redirect(URL1 + '/manage_catalogView?manage_tabs_message=Object%20Uncataloged') RESPONSE.redirect(
URL1 +
'/manage_catalogView?manage_tabs_message=Object%20Uncataloged')
def manage_catalogReindex(self, REQUEST, RESPONSE, URL1): def manage_catalogReindex(self, REQUEST, RESPONSE, URL1):
...@@ -238,7 +249,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -238,7 +249,8 @@ class ZCatalog(Folder, Persistent, Implicit):
elapse = time.time() - elapse elapse = time.time() - elapse
c_elapse = time.clock() - c_elapse c_elapse = time.clock() - c_elapse
RESPONSE.redirect(URL1 + RESPONSE.redirect(
URL1 +
'/manage_catalogAdvanced?manage_tabs_message=' + '/manage_catalogAdvanced?manage_tabs_message=' +
urllib.quote('Catalog Updated<br>' urllib.quote('Catalog Updated<br>'
'Total time: %s<br>' 'Total time: %s<br>'
...@@ -266,7 +278,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -266,7 +278,9 @@ class ZCatalog(Folder, Persistent, Implicit):
self._catalog.clear() self._catalog.clear()
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared') RESPONSE.redirect(
URL1 +
'/manage_catalogAdvanced?manage_tabs_message=Catalog%20Cleared')
def manage_catalogFoundItems(self, REQUEST, RESPONSE, URL2, URL1, def manage_catalogFoundItems(self, REQUEST, RESPONSE, URL2, URL1,
...@@ -304,8 +318,12 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -304,8 +318,12 @@ class ZCatalog(Folder, Persistent, Implicit):
elapse = time.time() - elapse elapse = time.time() - elapse
c_elapse = time.clock() - c_elapse c_elapse = time.clock() - c_elapse
RESPONSE.redirect(URL1 + '/manage_catalogView?manage_tabs_message=' + RESPONSE.redirect(
urllib.quote('Catalog Updated<br>Total time: %s<br>Total CPU time: %s' % (`elapse`, `c_elapse`))) URL1 +
'/manage_catalogView?manage_tabs_message=' +
urllib.quote(
'Catalog Updated<br>Total time: %s<br>Total CPU time: %s' %
(`elapse`, `c_elapse`)))
def manage_addColumn(self, name, REQUEST=None, RESPONSE=None, URL1=None): def manage_addColumn(self, name, REQUEST=None, RESPONSE=None, URL1=None):
...@@ -313,21 +331,27 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -313,21 +331,27 @@ class ZCatalog(Folder, Persistent, Implicit):
self.addColumn(name) self.addColumn(name)
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogSchema?manage_tabs_message=Column%20Added') RESPONSE.redirect(
URL1 +
'/manage_catalogSchema?manage_tabs_message=Column%20Added')
def manage_delColumns(self, names, REQUEST=None, RESPONSE=None, URL1=None): def manage_delColumns(self, names, REQUEST=None, RESPONSE=None, URL1=None):
""" Deprecated method. Use manage_delColumn instead. """ """ Deprecated method. Use manage_delColumn instead. """
# log a deprecation warning # log a deprecation warning
import warnings import warnings
warnings.warn("The manage_delColumns method of ZCatalog is deprecated"\ warnings.warn(
"since Zope 2.4.2.\n"\ "The manage_delColumns method of ZCatalog is deprecated"
"This method is only kept for backwards compatibility for a while\n"\ "since Zope 2.4.2.\n"
"and will go away in a future release.\n"\ "This method is only kept for backwards compatibility "
"\n"\ "for a while\n"
"Please use instead the manage_delColumn method.\n"\ "and will go away in a future release.\n"
"\n"
"Please use instead the manage_delColumn method.\n"
,DeprecationWarning) ,DeprecationWarning)
self.manage_delColumn(names, REQUEST=REQUEST, RESPONSE=RESPONSE, URL1=URL1)
self.manage_delColumn(names, REQUEST=REQUEST, RESPONSE=RESPONSE,
URL1=URL1)
def manage_delColumn(self, names, REQUEST=None, RESPONSE=None, URL1=None): def manage_delColumn(self, names, REQUEST=None, RESPONSE=None, URL1=None):
...@@ -339,15 +363,20 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -339,15 +363,20 @@ class ZCatalog(Folder, Persistent, Implicit):
self.delColumn(name) self.delColumn(name)
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogSchema?manage_tabs_message=Column%20Deleted') RESPONSE.redirect(
URL1 +
'/manage_catalogSchema?manage_tabs_message=Column%20Deleted')
def manage_addIndex(self, name, type, extra=None,REQUEST=None, RESPONSE=None, URL1=None): def manage_addIndex(self, name, type, extra=None,
""" add an index """ REQUEST=None, RESPONSE=None, URL1=None):
"""add an index """
self.addIndex(name, type,extra) self.addIndex(name, type,extra)
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogIndexes?manage_tabs_message=Index%20Added') RESPONSE.redirect(
URL1 +
'/manage_catalogIndexes?manage_tabs_message=Index%20Added')
def manage_deleteIndex(self, ids=None, REQUEST=None, RESPONSE=None, def manage_deleteIndex(self, ids=None, REQUEST=None, RESPONSE=None,
...@@ -355,14 +384,18 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -355,14 +384,18 @@ class ZCatalog(Folder, Persistent, Implicit):
""" Deprecated method. Use manage_delIndex instead. """ """ Deprecated method. Use manage_delIndex instead. """
# log a deprecation warning # log a deprecation warning
import warnings import warnings
warnings.warn("The manage_deleteIndex method of ZCatalog is deprecated"\ warnings.warn(
"since Zope 2.4.2.\n"\ "The manage_deleteIndex method of ZCatalog is deprecated"
"This method is only kept for backwards compatibility for a while\n"\ "since Zope 2.4.2.\n"
"and will go away in a future release.\n"\ "This method is only kept for backwards compatibility for a "
"\n"\ "while\n"
"Please use instead the manage_delIndex method.\n"\ "and will go away in a future release.\n"
"\n"
"Please use instead the manage_delIndex method.\n"
,DeprecationWarning) ,DeprecationWarning)
self.manage_delIndex(ids=ids, REQUEST=REQUEST, RESPONSE=RESPONSE, URL1=URL1)
self.manage_delIndex(ids=ids, REQUEST=REQUEST, RESPONSE=RESPONSE,
URL1=URL1)
def manage_delIndex(self, ids=None, REQUEST=None, RESPONSE=None, def manage_delIndex(self, ids=None, REQUEST=None, RESPONSE=None,
...@@ -380,7 +413,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -380,7 +413,9 @@ class ZCatalog(Folder, Persistent, Implicit):
self.delIndex(name) self.delIndex(name)
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogIndexes?manage_tabs_message=Index%20Deleted') RESPONSE.redirect(
URL1 +
'/manage_catalogIndexes?manage_tabs_message=Index%20Deleted')
def manage_clearIndex(self, ids=None, REQUEST=None, RESPONSE=None, def manage_clearIndex(self, ids=None, REQUEST=None, RESPONSE=None,
...@@ -398,7 +433,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -398,7 +433,9 @@ class ZCatalog(Folder, Persistent, Implicit):
self.clearIndex(name) self.clearIndex(name)
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogIndexes?manage_tabs_message=Index%20Cleared') RESPONSE.redirect(
URL1 +
'/manage_catalogIndexes?manage_tabs_message=Index%20Cleared')
def reindexIndex(self,name,REQUEST): def reindexIndex(self,name,REQUEST):
...@@ -413,8 +450,9 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -413,8 +450,9 @@ class ZCatalog(Folder, Persistent, Implicit):
self.catalog_object(obj, p, idxs=[name]) self.catalog_object(obj, p, idxs=[name])
def manage_reindexIndex(self, ids=None, REQUEST=None, RESPONSE=None, URL1=None): def manage_reindexIndex(self, ids=None, REQUEST=None, RESPONSE=None,
""" Reindex indexe(s) from a ZCatalog""" URL1=None):
"""Reindex indexe(s) from a ZCatalog"""
if not ids: if not ids:
return MessageDialog(title='No items specified', return MessageDialog(title='No items specified',
message='No items were specified!', message='No items were specified!',
...@@ -427,7 +465,10 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -427,7 +465,10 @@ class ZCatalog(Folder, Persistent, Implicit):
self.reindexIndex(name, REQUEST) self.reindexIndex(name, REQUEST)
if REQUEST and RESPONSE: if REQUEST and RESPONSE:
RESPONSE.redirect(URL1 + '/manage_catalogIndexes?manage_tabs_message=Reindexing%20Performed') RESPONSE.redirect(
URL1 +
'/manage_catalogIndexes'
'?manage_tabs_message=Reindexing%20Performed')
def availableSplitters(self): def availableSplitters(self):
...@@ -478,22 +519,25 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -478,22 +519,25 @@ class ZCatalog(Folder, Persistent, Implicit):
self._v_total = 0 self._v_total = 0
def uncatalog_object(self, uid): def uncatalog_object(self, uid):
""" wrapper around catalog """ """Wrapper around catalog """
self._catalog.uncatalogObject(uid) self._catalog.uncatalogObject(uid)
def uniqueValuesFor(self, name): def uniqueValuesFor(self, name):
""" returns the unique values for a given FieldIndex """ """Return the unique values for a given FieldIndex """
return self._catalog.uniqueValuesFor(name) return self._catalog.uniqueValuesFor(name)
def getpath(self, rid): def getpath(self, rid):
""" """Return the path to a cataloged object given a 'data_record_id_'
Return the path to a cataloged object given a 'data_record_id_'
""" """
return self._catalog.paths[rid] return self._catalog.paths[rid]
def getobject(self, rid, REQUEST=None): def getrid(self, path, default=None):
"""Return 'data_record_id_' the to a cataloged object given a 'path'
""" """
Return a cataloged object given a 'data_record_id_' return self._catalog.uids.get(path, default)
def getobject(self, rid, REQUEST=None):
"""Return a cataloged object given a 'data_record_id_'
""" """
obj = self.aq_parent.unrestrictedTraverse(self.getpath(rid)) obj = self.aq_parent.unrestrictedTraverse(self.getpath(rid))
if not obj: if not obj:
...@@ -542,8 +586,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -542,8 +586,8 @@ class ZCatalog(Folder, Persistent, Implicit):
return r return r
def searchResults(self, REQUEST=None, used=None, **kw): def searchResults(self, REQUEST=None, used=None, **kw):
""" """Search the catalog according to the ZTables search interface.
Search the catalog according to the ZTables search interface.
Search terms can be passed in the REQUEST or as keyword Search terms can be passed in the REQUEST or as keyword
arguments. arguments.
""" """
...@@ -783,9 +827,15 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -783,9 +827,15 @@ class ZCatalog(Folder, Persistent, Implicit):
self.addIndex(id,'TextIndex') self.addIndex(id,'TextIndex')
if converted: if converted:
RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=Indexes%20converted') RESPONSE.redirect(
URL1 +
'/manage_main?manage_tabs_message=Indexes%20converted')
else: else:
RESPONSE.redirect(URL1 + '/manage_main?manage_tabs_message=No%20indexes%20found%20to%20be%20converted') RESPONSE.redirect(
URL1 +
'/manage_main?'
'manage_tabs_message='
'No%20indexes%20found%20to%20be%20converted')
# #
...@@ -816,10 +866,10 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -816,10 +866,10 @@ class ZCatalog(Folder, Persistent, Implicit):
if base is None: if base is None:
raise ValueError, "Index type %s does not support addIndex" % type raise ValueError, "Index type %s does not support addIndex" % type
# This code is somewhat lame but every index type has its own function # This code is somewhat lame but every index type has its own
# signature *sigh* and there is no common way to pass additional parameters # function signature *sigh* and there is no common way to pass
# to the constructor. The suggested way for new index types is to use # additional parameters to the constructor. The suggested way
# an "extra" record. # for new index types is to use an "extra" record.
if 'extra' in base.__init__.func_code.co_varnames: if 'extra' in base.__init__.func_code.co_varnames:
index = apply(base,(name,), {"extra":extra,"caller":self}) index = apply(base,(name,), {"extra":extra,"caller":self})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment