control states to filter via global option; check for book topics, texts, and in quicksearch
This commit is contained in:
		
							parent
							
								
									513e730132
								
							
						
					
					
						commit
						e503d9c70c
					
				
					 3 changed files with 25 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -698,8 +698,16 @@ class BaseView(GenericView, I18NView):
 | 
			
		|||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    def states(self):
 | 
			
		||||
        return self.getStates()
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
    def allStates(self):
 | 
			
		||||
        return self.getStates(False)
 | 
			
		||||
 | 
			
		||||
    def getStates(self, forDisplay=True):
 | 
			
		||||
        result = []
 | 
			
		||||
        if not checkPermission(self.viewStatesPermission, self.context):
 | 
			
		||||
        if forDisplay and not checkPermission(self.viewStatesPermission, self.context):
 | 
			
		||||
            # do not display state information
 | 
			
		||||
            return result
 | 
			
		||||
        if IResource.providedBy(self.target):
 | 
			
		||||
            statesDefs = (self.globalOptions('organize.stateful.resource') or [])
 | 
			
		||||
| 
						 | 
				
			
			@ -711,6 +719,16 @@ class BaseView(GenericView, I18NView):
 | 
			
		|||
            result.append(stf)
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
    @Lazy
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -95,19 +95,10 @@ class Base(object):
 | 
			
		|||
        if self.editable:
 | 
			
		||||
            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):
 | 
			
		||||
        for c in self.getChildren():
 | 
			
		||||
            for stf in c.states or [None]:
 | 
			
		||||
                if self.checkState(stf):
 | 
			
		||||
                    yield c
 | 
			
		||||
                    break
 | 
			
		||||
            if c.checkState():
 | 
			
		||||
                yield c
 | 
			
		||||
 | 
			
		||||
    def getResources(self):
 | 
			
		||||
        relViews = super(Base, self).getResources()
 | 
			
		||||
| 
						 | 
				
			
			@ -120,12 +111,10 @@ class Base(object):
 | 
			
		|||
        idx = 0
 | 
			
		||||
        for rv in self.getResources():
 | 
			
		||||
            if rv.context.contentType.startswith('text/'):
 | 
			
		||||
                for stf in rv.states or [None]:
 | 
			
		||||
                    if self.checkState(stf):
 | 
			
		||||
                if rv.checkState():
 | 
			
		||||
                        idx += 1
 | 
			
		||||
                        result.append(rv)
 | 
			
		||||
                        self.images.append([])
 | 
			
		||||
                        break
 | 
			
		||||
            else:
 | 
			
		||||
                self.registerDojoLightbox()
 | 
			
		||||
                url = self.nodeView.getUrlForTarget(rv.context)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,7 +70,9 @@ class QuickSearchResults(NodeView):
 | 
			
		|||
        fv = FilterView(self.context, self.request)
 | 
			
		||||
        result = fv.apply(result)
 | 
			
		||||
        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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue