Skip to content

Commit

Permalink
Allow _ in view and column ids
Browse files Browse the repository at this point in the history
The introduction of SCRIPT_ID_DELIMITER should obviate the need for this
restriction.
  • Loading branch information
jean committed Nov 18, 2013
1 parent 771b829 commit c1a69a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 62 deletions.
2 changes: 0 additions & 2 deletions Products/CMFPlomino/PlominoColumn.py
Expand Up @@ -22,7 +22,6 @@

from Products.CMFPlomino.config import PROJECTNAME
from Products.CMFPlomino.browser import PlominoMessageFactory as _
from validator import isValidPlominoId
from Products.CMFPlomino.PlominoUtils import translate

import logging
Expand All @@ -39,7 +38,6 @@
description_msgid=_('CMFPlomino_help_column_id', default="Column id"),
i18n_domain='CMFPlomino',
),
validators=("isValidId", isValidPlominoId),
),
StringField(
name='SelectedField',
Expand Down
50 changes: 12 additions & 38 deletions Products/CMFPlomino/PlominoView.py
Expand Up @@ -43,7 +43,6 @@
from PlominoUtils import asUnicode, asList
from Products.CMFPlomino.config import *
from Products.CMFPlomino.browser import PlominoMessageFactory as _
from validator import isValidPlominoId
import interfaces

import logging
Expand All @@ -59,7 +58,6 @@
description_msgid=_('CMFPlomino_help_view_id', default="If changed after creation, database refresh is needed"),
i18n_domain='CMFPlomino',
),
validators = ("isValidId", isValidPlominoId),
),
TextField(
name='SelectionFormula',
Expand All @@ -86,23 +84,10 @@
description="Column used to sort the view",
format='select',
label_msgid=_('CMFPlomino_label_SortColumn', default="Sort column"),
description_msgid=_('CMFPlomino_help_SortColumn', default="Column used to sort the view, and by default for key lookup"),
description_msgid=_('CMFPlomino_help_SortColumn', default="Column used to sort the view"),
i18n_domain='CMFPlomino',
),
vocabulary="Column_vocabulary",
schemata="Sorting",
),
StringField(
name='KeyColumn',
widget=SelectionWidget(
label="Key column",
description="Column used for key lookup",
format='select',
label_msgid=_('CMFPlomino_label_KeyColumn', default="Key column"),
description_msgid=_('CMFPlomino_help_KeyColumn', default="Column used for key lookup, if different from sort column"),
i18n_domain='CMFPlomino',
),
vocabulary="Column_vocabulary",
vocabulary="SortColumn_vocabulary",
schemata="Sorting",
),
BooleanField(
Expand Down Expand Up @@ -437,11 +422,9 @@ def at_post_create_script(self):
""" Post create
"""
db = self.getParentDatabase()
refresh = not db.DoNotReindex
db.getIndex().createSelectionIndex(
'PlominoViewFormula_'+self.getViewName(),
refresh=refresh)
if refresh:
'PlominoViewFormula_'+self.getViewName())
if not db.DoNotReindex:
self.getParentDatabase().getIndex().refresh()

security.declarePublic('declareColumn')
Expand Down Expand Up @@ -695,30 +678,21 @@ def getPosition(self):

security.declarePublic('getDocumentsByKey')
def getDocumentsByKey(self, key, getObject=True):
""" Get documents where key or sorted column matches the given key
""" Get documents where the sorted column value matches the given key.
"""
index = self.getParentDatabase().getIndex()
keycolumn = self.getKeyColumn()
sortcolumn = self.getSortColumn()

if not (keycolumn or sortcolumn):
sortindex = self.getSortColumn()
if not sortindex:
return []

query = {'PlominoViewFormula_%s' % self.getViewName(): True}
sortkey = None
if keycolumn:
query[self.getIndexKey(keycolumn)] = key
elif sortcolumn:
sortkey = self.getIndexKey(sortcolumn)
query[sortkey] = key

sortindex = self.getIndexKey(sortindex)
results = index.dbsearch(
query,
sortkey,
{'PlominoViewFormula_%s' % self.getViewName(): True,
sortindex: key},
sortindex,
self.getReverseSorting())

if getObject:
# TODO: keep lazy
return [d.getObject() for d in results]
else:
return results
Expand Down Expand Up @@ -801,7 +775,7 @@ def getIndexKey(self, columnName):
key = ''
return key

def Column_vocabulary(self):
def SortColumn_vocabulary(self):
return [''] + [c.id for c in self.getColumns()]

registerType(PlominoView, PROJECTNAME)
Expand Down
22 changes: 0 additions & 22 deletions Products/CMFPlomino/validator.py
Expand Up @@ -11,25 +11,3 @@
USE_BBB_VALIDATORS = True

from zope.interface import implements


class PlominoIdValidator:
if USE_BBB_VALIDATORS:
__implements__ = (ivalidator,)
else:
implements(IValidator)

def __init__(self, name, title='', description=''):
self.name = name
self.title = title or name
self.description = description

def __call__(self, value, *args, **kwargs):
if '_' in value:
return ("The _ character is not allowed here.")
return True

isValidPlominoId = PlominoIdValidator(
'isValidPlominoId',
title='Plomino ids',
description='View and column ids must not contain underscores (_).')

0 comments on commit c1a69a1

Please sign in to comment.