Skip to content

Commit

Permalink
Use SCRIPT_ID_DELIMITER for handling view indexes
Browse files Browse the repository at this point in the history
Import * from config in a few more places, to get it.
  • Loading branch information
jean committed Nov 18, 2013
1 parent c1a69a1 commit eb1295c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Products/CMFPlomino/PlominoDesignManager.py
Expand Up @@ -202,7 +202,8 @@ def refreshDB(self):
#declare all the view formulas and columns index entries
for v_obj in self.getViews():
index.createSelectionIndex(
'PlominoViewFormula_' + v_obj.getViewName())
SCRIPT_ID_DELIMITER.join([
'PlominoViewFormula', v_obj.getViewName()]))
for c in v_obj.getColumns():
v_obj.declareColumn(c.getColumnName(), c, index=index)
# add fulltext if needed
Expand Down
4 changes: 3 additions & 1 deletion Products/CMFPlomino/PlominoForm.py
Expand Up @@ -1208,7 +1208,9 @@ def searchDocuments(self, REQUEST):

#index search
index = db.getIndex()
query = {'PlominoViewFormula_'+searchview.getViewName(): True}
view_formula_key = SCRIPT_ID_DELIMITER.join(
['PlominoViewFormula', searchview.getViewName()])
query = {view_formula_key: True}

for f in self.getFormFields(
includesubforms=True,
Expand Down
2 changes: 0 additions & 2 deletions Products/CMFPlomino/PlominoUtils.py
Expand Up @@ -54,8 +54,6 @@
except ImportError:
HAS_PLONE40 = False

from Products.CMFPlomino.AppConfig import SCRIPT_ID_DELIMITER

import logging
logger = logging.getLogger('Plomino')

Expand Down
36 changes: 24 additions & 12 deletions Products/CMFPlomino/PlominoView.py
Expand Up @@ -331,7 +331,9 @@ def getAllDocuments(self, start=1, limit=None, only_allowed=True,
sortindex=self.getIndexKey(sortindex)
if not reverse:
reverse = self.getReverseSorting()
query = {'PlominoViewFormula_'+self.getViewName(): True}
view_formula_key = SCRIPT_ID_DELIMITER.join(
['PlominoViewFormula', self.getViewName()])
query = {view_formula_key: True}
if fulltext_query:
query['SearchableText'] = fulltext_query
results=index.dbsearch(
Expand Down Expand Up @@ -423,7 +425,9 @@ def at_post_create_script(self):
"""
db = self.getParentDatabase()
db.getIndex().createSelectionIndex(
'PlominoViewFormula_'+self.getViewName())
SCRIPT_ID_DELIMITER.join(
['PlominoViewFormula', self.getViewName()])
)
if not db.DoNotReindex:
self.getParentDatabase().getIndex().refresh()

Expand All @@ -439,9 +443,10 @@ def declareColumn(self, column_name, column_obj, index=None):

if column_obj.Formula:
index.createIndex(
'PlominoViewColumn_%s_%s' % (
SCRIPT_ID_DELIMITER.join(
['PlominoViewColumn'
self.getViewName(),
column_name),
column_name]),
refresh=refresh)
else:
fieldpath = column_obj.SelectedField.split('/')
Expand All @@ -459,13 +464,15 @@ def declareColumn(self, column_name, column_obj, index=None):
else:
column_obj.setFormula("'Non-existing field'")
index.createIndex(
'PlominoViewColumn_%s_%s' % (
self.getViewName(), column_name),
SCRIPT_ID_DELIMITER.join(
['PlominoViewColumn',
self.getViewName(), column_name]),
refresh=refresh)
else:
index.createIndex(
'PlominoViewColumn_%s_%s' % (
self.getViewName(), column_name),
SCRIPT_ID_DELIMITER.join([
'PlominoViewColumn',
self.getViewName(), column_name]),
refresh=refresh)

security.declarePublic('getCategorizedColumnValues')
Expand Down Expand Up @@ -504,8 +511,10 @@ def getCategoryViewEntries(self, category_column_name, category_value):
else:
sortindex = self.getIndexKey(sortindex)

view_formula_key = SCRIPT_ID_DELIMITER.join(
['PlominoViewFormula', self.getViewName()])
return index.dbsearch(
{'PlominoViewFormula_'+self.getViewName(): True,
{view_formula_key: True,
self.getIndexKey(category_column_name): category_value},
sortindex,
self.getReverseSorting())
Expand Down Expand Up @@ -686,8 +695,10 @@ def getDocumentsByKey(self, key, getObject=True):
return []

sortindex = self.getIndexKey(sortindex)
view_formula_key = SCRIPT_ID_DELIMITER.join(
['PlominoViewFormula', self.getViewName()])
results = index.dbsearch(
{'PlominoViewFormula_%s' % self.getViewName(): True,
{view_formula_key: True,
sortindex: key},
sortindex,
self.getReverseSorting())
Expand Down Expand Up @@ -763,10 +774,11 @@ def tojson(self, REQUEST=None):
def getIndexKey(self, columnName):
""" Returns an index key if one exists.
We try to find a computed index ('PlominoViewColumn_*');
We try to find a computed index ('PlominoViewColumn*');
if not found, we look for a field.
"""
key = 'PlominoViewColumn_%s_%s' % (self.getViewName(), columnName)
key = SCRIPT_ID_DELIMITER.join(
['PlominoViewColumn', self.getViewName(), columnName])
if not key in self.getParentDatabase().plomino_index.Indexes:
fieldPath = self.getColumn(columnName).SelectedField.split('/')
if len(fieldPath) > 1:
Expand Down
2 changes: 1 addition & 1 deletion Products/CMFPlomino/fields/doclink.py
Expand Up @@ -25,7 +25,7 @@
from dictionaryproperty import DictionaryProperty
from Products.CMFPlomino.exceptions import PlominoScriptException
from Products.CMFPlomino.PlominoUtils import asUnicode
from Products.CMFPlomino.AppConfig import SCRIPT_ID_DELIMITER
from Products.CMFPlomino.config import *

class IDoclinkField(IBaseField):
""" Selection field schema
Expand Down
2 changes: 1 addition & 1 deletion Products/CMFPlomino/fields/events.py
Expand Up @@ -10,7 +10,7 @@
__author__ = """Eric BREHAULT <eric.brehault@makina-corpus.com>"""
__docformat__ = 'plaintext'

from Products.CMFPlomino.AppConfig import SCRIPT_ID_DELIMITER
from Products.CMFPlomino.config import *

def afterFieldModified(obj, event):
"""
Expand Down
2 changes: 1 addition & 1 deletion Products/CMFPlomino/fields/selection.py
Expand Up @@ -22,7 +22,7 @@
from Products.CMFPlomino.PlominoUtils import asUnicode

from jsonutil import jsonutil as json
from Products.CMFPlomino.AppConfig import SCRIPT_ID_DELIMITER
from Products.CMFPlomino.config import *


class ISelectionField(IBaseField):
Expand Down
5 changes: 3 additions & 2 deletions Products/CMFPlomino/index/PlominoCatalog.py
Expand Up @@ -16,6 +16,7 @@

# Plomino
from Products.CMFPlomino.PlominoUtils import asUnicode
from Products.CMFPlomino.config import *

try:
from DocumentTemplate.cDocumentTemplate import safe_callable
Expand All @@ -39,8 +40,8 @@ def recordify(self, obj):
record = []
# the unique id is always the first element
for name in self.names:
if name.startswith("PlominoViewColumn_"):
marker, viewname, columnname = name.split('_')
if name.startswith("PlominoViewColumn"+SCRIPT_ID_DELIMITER):
marker, viewname, columnname = name.split(SCRIPT_ID_DELIMITER)
if not obj.isSelectedInView(viewname):
v = None
else:
Expand Down
5 changes: 3 additions & 2 deletions Products/CMFPlomino/index/PlominoViewIndex.py
Expand Up @@ -14,6 +14,7 @@
from ZODB.POSException import ConflictError
from Products.PluginIndexes.common.UnIndex import UnIndex

from Products.CMFPlomino.config import *

class PlominoViewIndex(UnIndex):
""" Index for Plomino view selection formula.
Expand All @@ -35,8 +36,8 @@ def index_object(self, documentId, obj, threshold=None):
returnStatus = 0
parentdb = self.getParentDatabase()
doc = obj.__of__(parentdb)
if self.id.startswith("PlominoViewFormula_"):
param = self.id.split('_')
if self.id.startswith("PlominoViewFormula"+SCRIPT_ID_DELIMITER):
param = self.id.split(SCRIPT_ID_DELIMITER)
viewname = param[1]
newSelection = doc.isSelectedInView(viewname)
else:
Expand Down

0 comments on commit eb1295c

Please sign in to comment.