Beispiel #1
0
    def primary_action(self):
        action, param = None, None
        if 'reset' in self.request.keys():
            action = self.reset
            param = None
        elif 'search' in self.request.keys():
            action = self.search
            param = self.request.get('searchtext')
        elif 'filter' in self.request.keys():
            action = self.filter
            param = self.get_filter_terms()
        else:
            searchtext = session.get_last_search(self.context)
            terms = session.get_last_filter(self.context)
            if searchtext:
                action = self.search
                param = searchtext
            elif terms and terms.values() != ['!empty'] * 4:
                action = self.filter
                param = terms

        if not action:
            action = lambda param: None

        return action, param
Beispiel #2
0
    def update(self, **kwargs):
        if not self.available():
            return

        if hasattr(self.view, 'catalog'):
            catalog = self.view.catalog
            items = self.view.items
        else:
            catalog = self.catalog
            items = self.catalog.items

        self.items = items() if callable(items) else items

        # for the first category, count all items, for the others
        # count the ones in the current filter (might also be all)
        self.all_values = catalog.grouped_possible_values_counted()

        self.values = dict(cat1=self.all_values['cat1'])
        self.values.update(catalog.grouped_possible_values_counted(
            self.items, categories=['cat2', 'cat3', 'cat4']
        ))

        self.labels = self.directory.labels()
        self.select = session.get_last_filter(self.directory)
        self.searchtext = session.get_last_search(self.directory)
Beispiel #3
0
    def primary_action(self):
        action, param = None, None
        if 'reset' in self.request.keys():
            action = self.reset
            param = None
        elif 'search' in self.request.keys():
            action = self.search
            param = self.request.get('searchtext')
        elif 'filter' in self.request.keys():
            action = self.filter
            param = self.get_filter_terms()
        else:
            searchtext = session.get_last_search(self.context)
            terms = session.get_last_filter(self.context)
            if searchtext:
                action = self.search
                param = searchtext
            elif terms and terms.values() != ['!empty'] * 4:
                action = self.filter
                param = terms

        if not action:
            action = lambda param: None

        return action, param
Beispiel #4
0
    def update(self, **kwargs):
        if not self.available():
            return

        if hasattr(self.view, 'catalog'):
            catalog = self.view.catalog
            items = self.view.items
        else:
            catalog = self.catalog
            items = self.catalog.items

        self.items = items() if callable(items) else items

        # for the first category, count all items, for the others
        # count the ones in the current filter (might also be all)
        self.all_values = catalog.grouped_possible_values_counted()

        self.values = dict(cat1=self.all_values['cat1'])
        self.values.update(
            catalog.grouped_possible_values_counted(
                self.items, categories=['cat2', 'cat3', 'cat4']))

        self.labels = self.directory.labels()
        self.select = session.get_last_filter(self.directory)
        self.searchtext = session.get_last_search(self.directory)
Beispiel #5
0
 def filtered(self):
     if self.is_itemview:
         directory = self.context.get_parent()
         return any((
             session.get_last_search(directory),
             session.get_last_filter(directory)
         ))
     else:
         if 'search' in self.request.keys():
             return True
         if 'filter' in self.request.keys():
             return True
         return len(self.items) != self.unfiltered_count
Beispiel #6
0
    def update(self, **kwargs):
        if not self.available():
            return

        if hasattr(self.view, 'catalog'):
            catalog = self.view.catalog
            items = self.view.items
        else:
            catalog = self.catalog
            items = self.catalog.items

        self.items = items() if callable(items) else items
        self.filters = catalog.possible_values_sorted_as_sets(self.items)
        self.labels = self.directory.labels()
        self.select = session.get_last_filter(self.directory)
        self.searchtext = session.get_last_search(self.directory)