control states to filter via global option; check for book topics, texts, and in quicksearch

This commit is contained in:
Helmut Merz 2013-10-16 18:11:06 +02:00
parent 513e730132
commit e503d9c70c
3 changed files with 25 additions and 16 deletions

View file

@ -698,8 +698,16 @@ class BaseView(GenericView, I18NView):
@Lazy @Lazy
def states(self): def states(self):
return self.getStates()
@Lazy
def allStates(self):
return self.getStates(False)
def getStates(self, forDisplay=True):
result = [] result = []
if not checkPermission(self.viewStatesPermission, self.context): if forDisplay and not checkPermission(self.viewStatesPermission, self.context):
# do not display state information
return result return result
if IResource.providedBy(self.target): if IResource.providedBy(self.target):
statesDefs = (self.globalOptions('organize.stateful.resource') or []) statesDefs = (self.globalOptions('organize.stateful.resource') or [])
@ -711,6 +719,16 @@ class BaseView(GenericView, I18NView):
result.append(stf) result.append(stf)
return result return result
def checkState(self):
if not self.allStates:
return True
for stf in self.allStates:
option = self.globalOptions(
'organize.stateful.restrict.' + stf.statesDefinition)
if option:
return stf.state in option
return True
# controlling actions and editing # controlling actions and editing
@Lazy @Lazy

View file

@ -95,19 +95,10 @@ class Base(object):
if self.editable: if self.editable:
return 'index.html' return 'index.html'
def checkState(self, stateful):
if stateful is None:
return True
if stateful.statesDefinition == 'simple_publishing':
return stateful.state in ('published',)
return True
def children(self): def children(self):
for c in self.getChildren(): for c in self.getChildren():
for stf in c.states or [None]: if c.checkState():
if self.checkState(stf):
yield c yield c
break
def getResources(self): def getResources(self):
relViews = super(Base, self).getResources() relViews = super(Base, self).getResources()
@ -120,12 +111,10 @@ class Base(object):
idx = 0 idx = 0
for rv in self.getResources(): for rv in self.getResources():
if rv.context.contentType.startswith('text/'): if rv.context.contentType.startswith('text/'):
for stf in rv.states or [None]: if rv.checkState():
if self.checkState(stf):
idx += 1 idx += 1
result.append(rv) result.append(rv)
self.images.append([]) self.images.append([])
break
else: else:
self.registerDojoLightbox() self.registerDojoLightbox()
url = self.nodeView.getUrlForTarget(rv.context) url = self.nodeView.getUrlForTarget(rv.context)

View file

@ -70,7 +70,9 @@ class QuickSearchResults(NodeView):
fv = FilterView(self.context, self.request) fv = FilterView(self.context, self.request)
result = fv.apply(result) result = fv.apply(result)
result.sort(key=lambda x: x.title.lower()) result.sort(key=lambda x: x.title.lower())
return self.viewIterator(result) for v in self.viewIterator(result):
if v.checkState():
yield v
class Search(ConceptView): class Search(ConceptView):